🖥️ REST API developed in Spring Boot, including tests for the back-end
MIT License
Welcome to my Spring Boot app!
This project was developed to demonstrate how to build an API using Spring Boot. It has table relationships in the database and comprehensive unit and integration testing.
$ git clone https://github.com/Guilhermebit/spring-boot-rest-api.git
Install dependencies with Maven
Install docker: https://docs.docker.com/engine/install/
Run the following command:
./mvnw clean install
docker-compose up
This project includes a Python script that automates the application build process.
Here you can download Python: https://www.python.org/downloads/
To run the script, navigate to the project directory and execute:
py build.py
python build.py
The script performs the following steps:
Compiling an application: Use Maven Wrapper to compile an application with the correct command for the operating system:
mvnw.cmd clean package
./mvnw clean package
Stop and remove all Docker containers: Run docker-compose down
to ensure all containers are stopped and removed.
Building and starting Docker containers: Use docker-compose up --build -d
to build Docker images and start containers in the background.
The script was designed to simplify the process of building, stopping and restarting containers, saving time and making the process faster.
To test the HTTP requests below, the Postman tool was used.
If you choose to use Postman
, you can download the Collection
by clicking here, and import it into your Postman.
Here you can download Postman: https://www.postman.com/downloads/
TOKEN
and an ADMIN
role to access the routes:
POST /product
PUT /product/{id}
DELETE /product/{id}
POST /auth/register
Request (application/json)
Body
{
"login": "User1",
"password": 1234,
"role": "USER"
}
Response 201 (application/json)
Body
{
"data": "null",
"message": "Your registration was successful",
"status": 201
}
POST /auth/login
Request (application/json)
Body
{
"login": "User1",
"password": 1234,
}
Response 200 (application/json)
Body
{
"data": [
{
"token": "access_token",
}
],
"message": "access_token",
"status": 200
}
POST /product
Request (application/json)
Headers
Authorization: Bearer [access_token]
Body
{
"name": "t-shirt",
"price_in_cents": 5000
}
Response 201 (application/json)
Body
{
"data": [
{
"id": "c2fc6ab7-cdf1-46ee-be87-804df6be6731",
"name": "t-shirt",
"price_in_cents": 5000
}
],
"message": "",
"status": 201
}
GET /product
Request (application/json)
Headers
Authorization: Bearer [access_token]
Response 200 (application/json)
Body
{
"data": [
{
"id": "c2fc6ab7-cdf1-46ee-be87-804df6be6731",
"name": "t-shirt",
"price_in_cents": 5000
}
],
"message": "",
"status": 200
}
GET /product/{id}
Request (application/json)
Headers
Authorization: Bearer [access_token]
Response 200 (application/json)
Body
{
"data": [
{
"id": "c2fc6ab7-cdf1-46ee-be87-804df6be6731",
"name": "t-shirt",
"price_in_cents": 5000
}
],
"message": "",
"status": 200
}
GET /product/value/{3000}/{5000}
Request (application/json)
Headers
Authorization: Bearer [access_token]
Response 200 (application/json)
Body
{
"data": [
{
"id": "c2fc6ab7-cdf1-46ee-be87-804df6be6731",
"name": "t-shirt",
"price_in_cents": 5000
}
],
"message": "",
"status": 200
}
PUT /product/{id}
Request (application/json)
Headers
Authorization: Bearer [access_token]
Body
{
"name": "t-shirt blue",
"price_in_cents": 3000
}
Response 200 (application/json)
Body
{
"data": [
{
"id": "c2fc6ab7-cdf1-46ee-be87-804df6be6731",
"name": "t-shirt blue",
"price_in_cents": 3000
}
],
"message": "",
"status": 200
}
DELETE /product/{id}
Request (application/json)
Headers
Authorization: Bearer [access_token]
Response 204 (application/json)
Body
{
"data": null,
"message": "Product successfully deleted.",
"status": 204
}