In this mini-project, we want to implement a small service for maintaining users’ books. With this service, clients can create new user accounts. The requests for the book-related API undergo authentication.
- database package which is responsible for the CRUD operations.
- handlers package which contains the HTTP handlers of the project.
- authenticate package which handles the JWT authentication.
- config package which contains the configuration of this backend service.
path: /api/v1/auth/signup
Method: POST
This API creates a new user. Here is the model of the users
// Request
{
"user_name": "username",
"email": "[email protected]",
"password": "password",
"first_name": "fname",
"last_name": "lname",
"phone_number": "09136594879",
"gender": "gender"
}
path: /api/v1/auth/login
Method: POST
This API authenticates the user and returns the access token for the user.
// Request
{
"username": "username",
"password": "password"
}
// Response
{
"access_token": "abc.abc.abc"
}
path: /api/v1/books
Method: POST
This API creates a new book for logged-in users.
// Request Body
{
"name": "book_name",
"author": {
"first_name": "fname of author",
"last_name": "lname of author",
"birthday": "2000-01-12T00:00:00+03:30",
"nationality": "french"
},
"category": "book_category",
"volume": 1,
"published_at": "2000-01-12T00:00:00+03:30",
"summary": "this is a summary of the book.",
"table_of_contents": [
"fasle_1", "fasle_2"
],
"publisher": "publisher_name"
}
path: /api/v1/books
Method: GET
This API retrieves all books for all users and returns a list of books.
// Response of the /api/v1/books
{
"books" [
{
"name": "book_name",
"author": "<fname of author> <lname of author>",
"category": "book_category",
"volume": 1,
"published_at": "2000-01-12T00:00:00+03:30",
"summary": "this is a summary of the book.",
"publisher": "publisher_name"
},
{
"name": "book_name",
"author": "<fname of author> <lname of author>",
"category": "book_category",
"volume": 1,
"published_at": "2000-01-12T00:00:00+03:30",
"summary": "this is a summary of the book.",
"publisher": "publisher_name"
}
]
}
path: /api/v1/books/<id>
Method: GET
This API retrieves a specific book by id and returns the full information about that book.
// Response Body of /api/v1/books/13
{
"name": "book_name",
"author": {
"first_name": "fname of author",
"last_name": "lname of author",
"birthday": "2000-01-12T00:00:00+03:30",
"nationality": "french"
},
"category": "book_category",
"volume": 1,
"published_at": "2000-01-12T00:00:00+03:30",
"summary": "this is a summary of the book.",
"table_of_contents": [
"fasle_1", "fasle_2"
],
"publisher": "publisher_name"
}
path: /api/v1/books/<id>
Method: UPDATE
This API updates the information about books.
// Request body of the update API /api/v1/books/12
{
"name": "book_name_updated",
"category": "book_category_updated",
}
This API lets authenticated users delete the book they created.