This API allows you to perform CRUD (Create, Read, Update, Delete) operations on User Objects.
Java 8 or higher Maven Postgresql 15
-
Clone the repository to your local machine.
-
Run
mvn clean install
to build the project. -
Configure the application
The configuration for this API is stored in the application.properties
file. To configure the API or make changes to its behavior, you can edit this file. Here's how:
-
Navigate to the directory where the
application.properties
file is located. -
Open
application.properties
in a text editor of your choice. -
Modify the configuration settings as needed. Common configurations include database connection details, server port, or API secret keys.
Example application.properties
:
server.port = PORT
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=username
spring.datasource.password=password
- Package your application in a jar file using
mvn clean package
mvn install package
-
Run the package by using the jar application file found in the target folder:
java -jar your-application.jar
- Endpoint:
POST
- Description: Create a new user with a name and a value and email and value.
- Request Body:
{
"name": "John Doe",
"email" : "[email protected]"
}
- Response:
{
"id": 1,
"name": "John Doe",
"email" : "[email protected]"
}
- Endpoint:
GET /{user_id}
- Description: Retrieve a user by their ID.
- Response:
{
"id": 1,
"name": "John Doe",
"email" : "[email protected]"
}
- Endpoint:
PUT /{user_id}
- Description: Update a user's name and value by their ID.
- Request Body:
{
"name": "new name",
"email" : "new email"
}
- Response:
{
"name": "updated name",
"email" : "updated email"
}
- Endpoint:
DELETE /{user_id}
- Description: Delete a user by their ID.
- Response:
{
"message": "User deleted successfully"
}
- If the provided ID does not exist, you will receive a
404 Not Found
response. - If the provided email already exists, you will receive a "email already exists" response.
- If the provided name is not a string, you will receive a "name must be a string" response.
- If the provided email is not a string and in the wrong format, you will receive an "email must be a string" response.
- If the request body does not contain valid name and value fields, you will receive a
400 Bad Request
response. - If there is an internal server error, you will receive a
500 Internal Server Error
response.