BookService is developed in Go using net/http package and connected to MongoDB. Athorization to use the service is granted through JWT tokens with a lifespane of 5 minutes. JWT tokens are granted to registered users upon the sign in. The BookService supports GET, PUT, DELETE and POST requests for registered users.
Operations related to user.
User must register to be able to use the API. Send a JSON object containing "username" and "password" fields in a POST request to be registered. Example:
{
"username":"username",
"password":"password"
}
After registering, authenticate by sending a POST request containing your username and password. Upon successful authentication, you'll receive a JWT token with a set expiration time
In order to have the access to the core routes of the API, user must be authenticated and hold a valid JWT token in a Cookie.
{
"id": "_id",
"title": "title",
"author": "author",
"year": 1990,
"shortDesc": "description",
"genre": "comma, separated, list, of, genres"
}
Gets all available books from the database in JSON format.
Adds a book passed via this request to the database. Book's id must be null or empty string. Returns an Id of the inserted book if everything is well.
Gets a book in with the requested Id in JSON format.
To update a book, send along a JSON object with only those fields that you wish to update. For example, if I want to update only description and year, I'll send:
{
"year": 1990,
"shortDesc": "description"
}
You can't update the Id of the book.
The book with this id gets deleted from the database.