Restful API to perform crud operation.
- Git
- JDK 8 or later
- Maven 3.0 or later
- Spring Boot
- Docker
- H2 in memory database
These are the crud endpoints provided by the api:
- POST /person-rest-api/v1/persons: create a new person/persons
- GET /person-rest-api/v1/persons: retrieve all person details
- GET /person-rest-api/v1/persons/{id}: retrieve a person by id
- PUT /person-rest-api/v1/persons/{id}: update a person by id
- DELETE /person-rest-api/v1/persons/{id}: delete a person by id
- create person
Request:
curl --location --request POST 'http://localhost:9080/person-rest-api/v1/persons' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data-raw '{
"person": [
{
"first_name": "John",
"last_name": "Keynes",
"age": "29",
"favourite_colour": "red"
},
{
"first_name": "Sarah",
"last_name": "Singh",
"age": "54",
"favourite_colour": "blue"
},
{
"first_name": "DON",
"last_name": "Kumar",
"age": "34",
"favourite_colour": "blue"
}
]
}'
Response:
201 CREATED
{
"person": [
{
"id": 1,
"first_name": "John",
"last_name": "Keynes",
"age": "29",
"favourite_colour": "red"
},
{
"id": 2,
"first_name": "Sarah",
"last_name": "Singh",
"age": "54",
"favourite_colour": "blue"
},
{
"id": 3,
"first_name": "DON",
"last_name": "Kumar",
"age": "34",
"favourite_colour": "blue"
}
]
}
- retrieve all persons
Request:
curl --location --request GET 'http://localhost:9080/person-rest-api/v1/persons' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
Response:
200 OK
{
"person": [
{
"id": 2,
"first_name": "Sarah",
"last_name": "Singh",
"age": "54",
"favourite_colour": "blue"
},
{
"id": 3,
"first_name": "DON",
"last_name": "Kumar",
"age": "34",
"favourite_colour": "blue"
}
]
}
- Get person by id
Request:
curl --location --request GET 'http://localhost:9080/person-rest-api/v1/persons/2' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data-raw ''
Response:
200 OK
{
"person": [
{
"id": 2,
"first_name": "Sarah",
"last_name": "Singh",
"age": "54",
"favourite_colour": "blue"
}
]
}
- Update existing person
Request:
curl --location --request PUT 'http://localhost:9080/person-rest-api/v1/persons/1' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Cookie: JSESSIONID.671f16ca=node0xog1p4jt9wqj1qf5spsc515fb0.node0' \
--data-raw '{
"person": [
{
"first_name": "John",
"last_name": "Keynes",
"age": "29",
"favourite_colour": "red"
}
]
}'
Response:
200 OK
{
"person": [
{
"id": 2,
"first_name": "John",
"last_name": "Keynes",
"age": "29",
"favourite_colour": "red"
}
]
}
- Delete existing person
Request:
curl --location --request DELETE 'http://localhost:9080/person-rest-api/v1/persons/1' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json'
Response:
200 OK
To get started you can simply clone this repository using git:
git@github.com:reetesh043/person-rest-api.git
mvn spring-boot:run
- Create the package(jar)
mvn clean package
- Build the image
docker build -t person-rest-api .
- Check generated image(optional)
docker images
4.Run the image and start application. It will start application on port 9080
docker run -p 9080:9080 person-rest-api
- It will provide the status if api is up and running:
http://localhost:9080/person-rest-api/v1/actuator/health
- Api documentation will be available at:
http://localhost:9080/person-rest-api/v1/v2/api-docs
- Api swagger will be available at:
http://localhost:9080/person-rest-api/v1/swagger-ui.html
- Api swagger is also available at:
https://github.com/reetesh043/person-rest-api/blob/main/src/main/resources/person-rest-api_swagger.yaml
https://github.com/reetesh043/person-rest-api/blob/main/src/main/resources/person-rest-api.postman_collection.json