An API for managing books.
POST /books
-> Create a new bookGET /books
-> Return a list of all booksGET /books/{id}
-> Return details of a specific bookPATCH /books/{id}
-> Update a specific bookDELETE /books/{id}
-> Delete a specific book- All responses are returned in JSON format.
- The HTTP response status code for successful requests is 200, and requests to non-existent endpoints return 404.
Create a new book.
-
Request format:
- Required fields:
title
,author
,publication_year
,genre
,price
- Required fields:
-
Success response:
{
"message": "Book successfully created!",
"book": {
"id": 1,
"title": "Go Programming",
"author": "John Doe",
"publication_year": "2022",
"genre": "Programming",
"price": "3500",
"created_at": "2024-09-07T10:00:00Z",
"updated_at": "2024-09-07T10:00:00Z"
}
}
- Failure response:
{
"message": "Book creation failed",
"required": "title, author, publication_year, genre, price"
}
Returns a list of all books.
- Request format:
GET /books/
- Response format:
{
"books": [
{
"id": 1,
"title": "Go Programming",
"author": "John Doe",
"publication_year": "2022",
"genre": "Programming",
"price": "3500"
},
{
"id": 2,
"title": "Introduction to Kubernetes",
"author": "Jane Smith",
"publication_year": "2021",
"genre": "Technology",
"price": "4000"
}
]
}
Returns the details of the book with the specified id.
- Request format:
GET /books/{id}
- Response format:
{
"message": "Book details by id",
"book": {
"id": 1,
"title": "Go Programming",
"author": "John Doe",
"publication_year": "2022",
"genre": "Programming",
"price": "3500"
}
}
Updates the book with the specified id and returns the updated book.
- Request format: PATCH /books/{id}
- Fields: One or more of
title
,author
,publication_year
,genre
,price
- Fields: One or more of
- Success response:
{
"message": "Book successfully updated!",
"book": {
"id": 1,
"title": "Go Programming Advanced",
"author": "John Doe",
"publication_year": "2022",
"genre": "Programming",
"price": "4000"
}
}
- Failure response:
{
"message": "Book update failed",
"required": "title, author, publication_year, genre, price"
}
Deletes the book with the specified id.
- Request format:
DELETE /books/{id}
- Success response:
{
"message": "Book successfully removed!"
}
- Failure response:
{
"message": "No book found"
}