- Clone this repository:
git clone https://github.com/hendisantika/springboot-rest-error-handling.git
- Go inside the folder:
cd springboot-rest-error-handling
- Run the application:
mvn clean spring-boot:run
- Open REST Client App e.g POSTMAN or curl with jq.
- Import POSTMAN Collection
List All Books
curl --location --request GET 'http://localhost:8080/books' | jq.
[
{
"id": 1,
"name": "A Guide to the Bodhisattva Way of Life",
"author": "Santideva",
"price": 15.41
},
{
"id": 2,
"name": "The Life-Changing Magic of Tidying Up",
"author": "Marie Kondo",
"price": 9.69
},
{
"id": 3,
"name": "Refactoring: Improving the Design of Existing Code",
"author": "Martin Fowler",
"price": 47.99
},
{
"id": 4,
"name": "A Guide to be Spring Boot Developer Way of Life",
"author": "Hendi Santika",
"price": 15.41
},
{
"id": 5,
"name": "A Guide to be Spring Boot Developer as Way of Life",
"author": "Hendi Santika Hiruzen",
"price": 20.2
}
]
Add New Book
curl --location --request POST 'http://localhost:8080/books' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "A Guide to be Spring Boot Developer Way of Life",
"author": "Hendi Santika",
"price": 15.41
}' | jq .
{
"id": 6,
"name": "A Guide to be Spring Boot Developer Way of Life",
"author": "Hendi Santika",
"price": 15.41
}
Find Book By ID
curl --location --request GET 'http://localhost:8080/books/4' | jq .
{
"id": 4,
"name": "A Guide to be Spring Boot Developer Way of Life",
"author": "Hendi Santika",
"price": 15.41
}
Save or Update Book
curl --location --request PUT 'http://localhost:8080/books/5' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "A Guide to be Spring Boot Developer as Way of Life",
"author": "Hendi Santika",
"price": 20.20
}' | jq .
{
"id": 5,
"name": "A Guide to be Spring Boot Developer as Way of Life",
"author": "Hendi Santika",
"price": 20.2
}
Update Author Only
curl --location --request PATCH 'http://localhost:8080/books/5' \
--header 'Content-Type: application/json' \
--data-raw '{
"author": "Hendi Santika Hiruzen"
}' | jq .
{
"id": 5,
"name": "A Guide to be Spring Boot Developer as Way of Life",
"author": "Hendi Santika Hiruzen",
"price": 20.2
}
Delete a Book by ID
curl --location --request DELETE 'http://localhost:8080/books/6'