Git Product home page Git Product logo

hng_internship_backend_stage_2_task's Introduction

REST API Documentation

This documentation outlines the details for the REST API developed to perform CRUD operations on a "person" resource. The API provides endpoints for creating, reading, updating, and deleting person records. It ensures secure interactions with the database to prevent common vulnerabilities like SQL injections.

Endpoints

CREATE: Adding a New Person

  • Endpoint: /api
  • HTTP Method: POST

Request Format

{
    "name": "John Doe",
}

Response Format

{
    "message": "User created successfully",
    "statusCode": 201,
    "time": "2023-09-13T10:30:00",
    "userId": 1
}

READ: Fetching Details of a Person

  • Endpoint: /api/{user_id}
  • HTTP Method: GET

Response Format (Successful)

{
    "id": 1,
    "name": "John Doe",
    "createdAt": "2023-09-13T10:30:00",
    "updatedAt": "2023-09-13T10:45:00"
}

Response Format (User Not Found)

{
    "message": "User not found",
    "statusCode": 404,
    "time": "2023-09-13T11:00:00"
}

UPDATE: Modifying Details of an Existing Person

  • Endpoint: /api/{user_id}
  • HTTP Method: PUT

Request Format

{
    "name": "Updated Name",
}

Response Format (Successful)

{
    "message": "User updated successfully",
    "statusCode": 200,
    "time": "2023-09-13T10:45:00"
}

Response Format (User Not Found)

{
    "message": "User not found",
    "statusCode": 404,
    "time": "2023-09-13T11:00:00"
}

DELETE: Removing a Person

  • Endpoint: /api/{user_id}
  • HTTP Method: DELETE

Response Format (Successful)

{
    "message": "User deleted successfully",
    "statusCode": 200,
    "time": "2023-09-13T11:15:00"
}

Response Format (User Not Found)

{
    "message": "User not found",
    "statusCode": 404,
    "time": "2023-09-13T11:30:00"
}

Sample Usage

Creating a New Person

Request:

POST /api
Content-Type: application/json

{
    "name": "John Doe",
    "age": 30
}

Response:

{
    "message": "User created successfully",
    "statusCode": 201,
    "time": "2023-09-13T10:30:00",
    "userId": 1
}

Fetching Details of a Person

Request:

GET /api/1

Response (Successful):

{
    "id": 1,
    "message": "John Doe",
    "createdAt": "2023-09-13T10:30:00",
    "updatedAt": "2023-09-13T10:45:00"
}

Response (User Not Found):

{
    "message": "User not found",
    "statusCode": 404,
    "time": "2023-09-13T11:00:00"
}

Modifying Details of an Existing Person

Request:

PUT /api/1
Content-Type: application/json

{
    "name": "Updated Name",
}

Response (Successful):

{
    "message": "User updated successfully",
    "statusCode": 200,
    "time": "2023-09-13T10:45:00"
}

Response (User Not Found):

{
    "message": "User not found",
    "statusCode": 404,
    "time": "2023-09-13T11:00:00"
}

Removing a Person

Request:

DELETE /api/1

Response (Successful):

{
    "message": "User deleted successfully",
    "statusCode": 200,
    "time": "2023-09-13T11:15:00"
}

Response (User Not Found):

{
    "message": "User not found",
    "statusCode": 404,
    "time": "2023-09-13T11:30:00"
}

Known Limitations and Assumptions

  • The API assumes that a person's name should contain only letters.
  • The API does not support authentication or authorization. Access control should be implemented separately.
  • Error messages are generic and do not provide specific details on validation failures.
  • This documentation assumes that the API is deployed and accessible.

Setup and Deployment Instructions

To set up and deploy the API locally or on a server, follow these general steps:

  1. Clone the repository containing the API source code.
  2. Ensure that you have Java and Maven installed on your system.
  3. Configure the database connection details in the application.properties file.
  4. Build the application using Maven: mvn clean install.
  5. Run the application: java -jar target/your-api.jar.
  6. The API will be accessible at http://localhost:8080 by default. Update the base URL as needed.
  7. You can deploy the API to a server by deploying the generated JAR file and configuring a production database.

Please note that specific setup and deployment steps may vary depending on your environment and deployment platform.

Project UML Diagram

User UML

Person Model Diagram

hng_internship_backend_stage_2_task's People

Contributors

angeloobeta avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.