Each book object contains the following fields:
{
"id": 1,
"title": "Book Title",
"author": "Author Name",
"description": "Brief description of the book",
"publicationDate": "YYYY-MM-DD",
"coverImage": "https://covers.example.com/cover-id.jpg"
}
Used for administrator login.
-
Description: Authenticate with a username and password. If authentication is successful, a success message is returned (in the JWT version, a token is also returned).
-
Request:
- URL:
/login
- Method:
POST
- Request Body:
{ "username": "admin", "password": "password123" }
- URL:
-
Response:
- Success Response:
- Status Code:
200 OK
- Response Body (varies based on the version):
- File-based authentication:
{ "message": "Login successful" }
- JWT-based authentication:
{ "token": "your_jwt_token" }
- File-based authentication:
- Status Code:
- Error Response:
- Status Code:
401 Unauthorized
- Response Body:
{ "message": "Invalid username or password" }
- Status Code:
- Success Response:
Retrieve all books.
-
Description: This endpoint allows any user to retrieve a list of books.
-
Request:
- URL:
/books
- Method:
GET
- URL:
-
Response:
- Success Response:
- Status Code:
200 OK
- Response Body (example):
[ { "id": 1, "title": "Book 1", "author": "Author 1", "description": "Description of Book 1", "publicationDate": "1851-10-18", "coverImage": "https://covers.example.com/cover1.jpg" }, { "id": 2, "title": "Book 2", "author": "Author 2", "description": "Description of Book 2", "publicationDate": "1869-01-01", "coverImage": "https://covers.example.com/cover2.jpg" } ]
- Status Code:
- Success Response:
Retrieve a specific book by ID.
-
Description: This endpoint allows any user to retrieve detailed information about a specific book by providing its unique ID.
-
Request:
- URL:
/books/:id
- Method:
GET
- URL:
-
Response:
- Success Response:
- Status Code:
200 OK
- Response Body (example):
{ "id": 1, "title": "Book 1", "author": "Author 1", "description": "Description of Book 1", "publicationDate": "1851-10-18", "coverImage": "https://covers.example.com/cover1.jpg" }
- Status Code:
- Error Response :
- Book Not Found
- Status Code:
404 Not Found
- Response Body:
{ "message": "Book not found" }
- Success Response:
Add a new book (admin only).
-
Description: Only logged-in administrators can add a new book.
-
Request:
- URL:
/books
- Method:
POST
- Request Body:
{ "title": "New Book", "author": "Author Name", "description": "Book description", "publicationDate": "YYYY-MM-DD", "coverImage": "https://covers.example.com/newcover.jpg" }
- URL:
-
Response:
- Success Response:
- Status Code:
201 Created
- Response Body:
{ "id": 3, "title": "New Book", "author": "Author Name", "description": "Book description", "publicationDate": "YYYY-MM-DD", "coverImage": "https://covers.example.com/newcover.jpg" }
- Status Code:
- Error Response :
- If not logged in for JWT-based authentication
- Status Code:
401 Unauthorized
- Response Body:
{ "message": "Invalid user." }
- Success Response:
Update a book by its ID (admin only).
-
Description: Allows an admin to update the details of a specific book by its ID.
-
Request:
- URL:
/books/:id
- Method:
PUT
- Request Body:
{ "title": "Updated Book Title", "author": "Updated Author", "description": "Updated description", "publicationDate": "YYYY-MM-DD", "coverImage": "https://covers.example.com/newcover.jpg" }
- URL:
-
Response:
- Success Response:
- Status Code:
200 OK
- Response Body:
{ "id": 1, "title": "Updated Book Title", "author": "Updated Author", "description": "Updated description", "publicationDate": "YYYY-MM-DD", "coverImage": "https://covers.example.com/newcover.jpg" }
- Status Code:
- Error Response
- If not logged in for JWT-based authentication
- Status Code:
401 Unauthorized
- Response Body (example):
{ "message": "Invalid user." }
- Book not found
- Status Code:
404 Not Found
- Response Body (example):
{ "message": "Book not found" }
- Success Response:
Delete a book by its ID (admin only).
-
Description: Only logged-in administrators can delete a book by its ID.
-
Request:
- URL:
/books/:id
- Method:
DELETE
- URL:
-
Response:
- Success Response:
- Status Code:
204 No Content
- Response Body:
{ }
- Status Code:
- Error Response
- If not logged in for JWT-based authentication
- Status Code:
401 Unauthorized
- Response Body (example):
{ "message": "Invalid user." }
- Book not found
- Status Code:
404 Not Found
- Response Body (example):
{ "message": "Book not found" }
- Success Response:
- 200 OK: Request was successful.
- 201 Created: Resource was successfully created.
- 401 Unauthorized: Authentication failed (invalid credentials).
- 403 Forbidden: Access denied (user is not authorized).
- 404 Not Found: Resource not found (e.g., book with specified ID doesn't exist).