Sample of REST service in Java.
Technologies:
- Spring Boot
- JPA, Spring Data, Pagination
- Flyway DB migrations
- Spring Security (API key auth)
- Custom Exception handler
- DTO, Validation
Clone repository
git clone https://github.com/dawidgorecki/rest-service-java.git
Run MySQL database
docker run -p 3307:3306 --name rest_service -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=rest_service -d mysql
Go inside folder and run application
cd rest-service-java
# on linux with maven wrapper
./mvnw clean install spring-boot:run
API key passed in HTTP header.
Key: AUTH_API_KEY
Value: secret_key
POST http://localhost:8080/api/v1/tasks
{
"name": "My task",
"description": "Task description",
"deadline": "2022-12-12"
}
GET http://localhost:8080/api/v1/tasks
GET http://localhost:8080/api/v1/tasks?page=0&size=2&sort=id,desc
GET http://localhost:8080/api/v1/tasks/5
PUT http://localhost:8080/api/v1/tasks/1
{
"name": "My updated task",
"description": "New description",
"deadline": "2022-12-15"
}
DELETE http://localhost:8080/api/v1/tasks/1
PATCH http://localhost:8080/api/v1/tasks/1