The book API help to obtain information about a specific book or a lot of books as you want to query.
To start first run the command
npm install
then
to run like a developer just run the command
npm run dev
or to build it
npm run build && npm run start
javascript node.js npm
ATTENTION:
- Some test only works when is run one time, beacuse it create users and users can be unique.
- The server is listening to port 3000 locally
To run the test:
npm run test
or
mocha
The book model is constructed like this:
{
"title": "String",
"author": "String",
"year": "Number",
"pages": "Number",
"description": "String",
"image": "String"
}
The title of the book. Type: String. Required.
The author of the book. Type: String. Required.
The publishing year of the book. Type: Number. Required.
The amount of pages of the book. Type: Number. Required.
The description of the book Type: String Required
The url of the book image. Type: String. Required
The user construction is created like this:
{
"username": "String",
"email": "String",
"password": "String",
"roles": []
}
The user, username. Type: String. Required and Unique.
The user email. Type: String. Required and Unique.
The user password. Type: String. Required.
The user roles. Type: Array. Default role is user.
The authentication is used to sign in or sign up. The sign up can be performed by anyone as well as the sing in. But only the admins or moderators previous registerd can add users by the user class, update, or delete them.
The sign up require:
{
"username": "somename",
"email": "[email protected]",
"password": "password"
}
When you sign up as a user it gives you, your user and a token to perform basic operations to the API, almost every get request.
The sign in require:
{
"email": "[email protected]",
"password": "password"
}
When you sign in the API return the user and a token to use. The tokes expires depends on the role:
- admin or moderator: Unlimited for every sign in
- user: 24 hours for every sign in
API for a work test. :)