This project provide books directory RESTful api, for performing CRUD operations on books.
Every request must follow pattern https://<url to page>/api/<resource>
Every book has atleast following attributes
- _id
- title
- author
- pages
- price
Querying books require authentication read User for more details.
Requires Authentication A
GET
request to/api/books
return all books.
Requires Authentication A
GET
request to/api/books/:bookId
return all books.
where a bookId
must be provided as path parameter.
eg: /api/books/61b8d895d19066065c8384bc
Requires Admin Authentication A
POST
request to/api/books/
with JSON payload as body containing following attributes
- title
- author
- pages
- price
eg:
{
"titile": "Book title",
"author": "Author name",
"pages": 99,
"price": 100
}
Requires Admin Authentication A
PUT
request to/api/books/:bookId
with JSON payload as body containing following attributes
- title
- author
- pages
- price
eg:
{
"titile": "Book title",
"author": "Author name",
"pages": 99,
"price": 100
}
where a bookId
must be provided as path parameter.
eg: /api/books/61b8d895d19066065c8384bc
Requires Admin Authentication A
DELETE
request to/api/books/:bookId
will delete corresponding book. where abookId
must be provided as path parameter.
eg: /api/books/61b8d895d19066065c8384bc
Every user has following parameters.
- _id
- password
A POST
request to /api/user/
with JSON payload as body containing following attributes
- password will create a new user.
eg:
{
"email": "johndoe@email.com",
"password": "veryStrongPassword",
}
It will return a JWT as a header "x-auth-token". Send this token with every request that requires authentication as a header "x-auth-token".
A POST
request to /api/user/auth
with JSON payload as body containing following attributes
- password
eg:
{
"email": "johndoe@email.com",
"password": "veryStrongPassword",
}
It will return a JWT as a header "x-auth-token". Send this token with every request that requires authentication as a header "x-auth-token".
It requires 2 environment variables.
- DBLink: mongoDB database link with username and password
- JWTPrivateKey: For signing JWT tokens.