This project is a REST API built with Spring Boot, using JWT for authentication and PostgreSQL as the database. The application is fully containerized with Docker.
Run the following command to build the image without using cache:
docker-compose build --no-cache
docker-compose up -d
docker ps
brew services list
brew services stop postgresql
sudo lsof -i :5432
netstat -ano | findstr :5432
The API is served over HTTPS at https://localhost
Since it uses a self-signed certificate, curl commands require the -k flag to skip SSL verification
In a browser, you may need to accept the certificate manually the first time
https://localhost/swagger-ui/index.html
curl -X POST https://localhost/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "admin"}'
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"username": "admin",
"roleId": 1
}
curl -X GET https://localhost/user/1 \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
curl -X GET https://localhost/users \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json"
curl -X GET https://localhost:8080/books \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json"
curl -X GET https://localhost:8080/books/1 \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json"
curl -X POST https://localhost:8080/books \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "Watchmen (Edició Especial)",
"authorId": 1,
"isbn": "978-1779501127",
"publishedDate": "1986-09-01",
"genreId": 2,
"available": false
}'
curl -X PUT https://localhost:8080/books/1 \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "Watchmen (Edició Especial)",
"authorId": 1,
"isbn": "978-1779501127",
"publishedDate": "1986-09-01",
"genreId": 2,
"available": false
}'
curl -X GET https://localhost:8080/authors \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json"
curl -X GET https://localhost:8080/authors/1 \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json"
curl -X POST https://localhost:8080/authors \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Alan Moore",
"birthDate": "1953-11-18",
"nationality": "Regne Unit"
}'
curl -X PUT https://localhost:8080/authors/11 \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Alan Moore Actualitzat",
"birthDate": "1953-11-18",
"nationality": "Regne Unit"
}'
curl -X GET https://localhost:8080/genres \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json"
curl -X GET https://localhost:8080/genres/1 \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json"
curl -X POST https://localhost:8080/genres \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Còmic",
"description": "Històries explicades mitjançant vinyetes i diàlegs curts."
}'
curl -X PUT https://localhost:8080/genres/5 \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Còmic Actualitzat",
"description": "Gènere narratiu gràfic, amb vinyetes i diàlegs curts."
}'