API that implements CRUD Operations.
Create an API that can implement CRUD operations, any developer can use it with your front-end projects because this API always returns the same format.
This API simulates a contacts book, where the user can create contacts and add them to the book directory
This project is run with maven, you can run this project in different ways:
Run this command by the command line in the root directory to execute the app with maven
mvn spring-boot:run
Execute the script of maven for run the project
./mvnw spring-boot:run
first: you need build jar file with this command
mvn package
second: you run the jar file before created
java -jar target/[name-file-jar]
the jar file after created is inside the folder target
The app have a four endpoint at this moment
POST http://host:port/api/contact/save
GET http://host:port/api/contact
PATCH http://host:port/api/contact
DELETE http://host:port/api/contact/{id}
the id is a parameter, you have to provided it in the URL.
This project has an implementation documentation by swagger,which you can see in this link:
http://host:port/swagger-ui/index.html
The project have a postman collection
We have some entities to handle data provided from the request and data to response to the client.
Contact
{
"id": 1,
"name": "john",
"phoneNumber": "8745126732",
"phoneType": "mobile",
"createdAt": "24-11-2021 09:38",
"updatedAt": "24-11-2021 09:38"
}
we handle a universal response for all API with this format example saved user:
{
"timeStamp": "24-Nov-2021 09:38",
"statusCode": 200,
"status": "CREATED",
"message": "contact saved",
"developerMessage": "the contact is created successfully",
"data": {
"contact": {
"id": 3,
"name": "john",
"phoneNumber": "8745126732",
"phoneType": "mobile",
"createdAt": "24-11-2021 09:38",
"updatedAt": "24-11-2021 09:38"
}
}
}
The property data in the response always change depending on the endpoint to you call response when error is occurred:
{
"timeStamp": "24-Nov-2021 09:43",
"statusCode": 409,
"status": "CONFLICT",
"reason": "409 CONFLICT",
"message": "exception occurred",
"developerMessage": "exception because try save duplicated data",
"data": {
"error": "you try save a contact, but the phone number already is registered, remember phone numbers be uniques"
}
}
create user
{
"username": "john",
"phoneNumber": "552678456",
"phoneType": "mobile"
}
update user
{
"id": 1,
"username": "john",
"phoneNumber": "552678456",
"phoneType": "mobile"
}
if some data is not provided in the request, return error with message
I like to track one methodology for the development process of my project, which I don't know, helps me to focus on creating one functionality or doing one task only.
you can see this process with Notion file in this link: notion link
- Spring Boot: framework
- MySQL: database implementation
- OpenAPI: with swagger to document this API
- SpringBoot JPA: to handle logic to persist data in database
- AssertJ: tests more structured
- Javax Validations: bean validation for fields in the request data
CI Pipeline GitHub Action name
This project has Continuous Delivery (CI) through a GitHub Action, this action simply runs the test and makes sure that the test always pass.
The GitHub Action CI Pipeline will be triggered every time a pull request is made to the main branch of the project.
Basic flow chart