- JDK 23
- Docker
docker-compose.yml file contained mysql service that your Spring Boot Application can access
services:
mysql:
container_name: mysql
image: mysql:9.2.0
restart: always
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: /rootPwd
MYSQL_DATABASE: bookdb
MYSQL_USER: bookusr
MYSQL_PASSWORD: /BookAdm4546
volumes:
- type: volume
source: mysql-data
target: /var/lib/mysql
volumes:
mysql-data:
- Start mysql service using docker-compose
docker compose up -d
- Create database schema and initial data with
create-schema.sh
./create-schema.sh
create-schema.sh
will use DDL from schema.sql
file and data from data.sql
- If you want to drop the schema you can use
drop-schema.sh
that will use script located indrop-schema.sql
./drop-schema.sh
via Maven
./mvnw spring-boot:run
Unit Test
./mvnw test
Integration Test
./mvnw failsafe:integration-test
GET /books?author={author}
Request Parameters
- author = Name of the book's author
Request
GET http://localhost:8080/books?author=Colleen Hoover
Response (200 OK)
[
{
"id": 14,
"title": "It Ends With Us",
"author": "Colleen Hoover",
"publishedDate": "2559-08-02"
},
{
"id": 15,
"title": "Verity",
"author": "Colleen Hoover",
"publishedDate": "2561-12-07"
}
]
POST /books
Request Body
- title = Book's title
- author = Book's author
- publishedDate = Book's published date
Request
POST http://localhost:8080/books
Content-Type: application/json
{
"title": "Lord of the ring",
"author": "Pat",
"publishedDate": "2564-06-07"
}
Response (201 Created)
{
"id": 65,
"title": "Lord of the ring",
"author": "Pat",
"publishedDate": "2564-06-07"
}
Request
POST http://localhost:8080/books
Content-Type: application/json
{
"title": "",
"author": "Pat",
"publishedDate": "2564-06-07"
}
Response (400 Bad Request)
{
"fieldErrors": [
{
"field": "title",
"rejectedValue": "",
"message": "title must not be empty"
}
]
}