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.
- Endpoint:
/api
- HTTP Method: POST
{
"name": "John Doe",
}
{
"message": "User created successfully",
"statusCode": 201,
"time": "2023-09-13T10:30:00",
"userId": 1
}
- Endpoint:
/api/{user_id}
- HTTP Method: GET
{
"id": 1,
"name": "John Doe",
"createdAt": "2023-09-13T10:30:00",
"updatedAt": "2023-09-13T10:45:00"
}
{
"message": "User not found",
"statusCode": 404,
"time": "2023-09-13T11:00:00"
}
- Endpoint:
/api/{user_id}
- HTTP Method: PUT
{
"name": "Updated Name",
}
{
"message": "User updated successfully",
"statusCode": 200,
"time": "2023-09-13T10:45:00"
}
{
"message": "User not found",
"statusCode": 404,
"time": "2023-09-13T11:00:00"
}
- Endpoint:
/api/{user_id}
- HTTP Method: DELETE
{
"message": "User deleted successfully",
"statusCode": 200,
"time": "2023-09-13T11:15:00"
}
{
"message": "User not found",
"statusCode": 404,
"time": "2023-09-13T11:30:00"
}
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
}
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"
}
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"
}
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"
}
- 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.
To set up and deploy the API locally or on a server, follow these general steps:
- Clone the repository containing the API source code.
- Ensure that you have Java and Maven installed on your system.
- Configure the database connection details in the
application.properties
file. - Build the application using Maven:
mvn clean install
. - Run the application:
java -jar target/your-api.jar
. - The API will be accessible at
http://localhost:8080
by default. Update the base URL as needed. - 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.