The main goal of this project is to exercise:
- ExpressJS' basic routing features.
- GET and POST HTTP methods.
- Error handling.
- General protocols and standards.
- Documentation and organization.
There are 3 main features in this project:
- Get all the users from the database
- Get a specific user from the database
- Add a user to the database
Shows the home page of the project.
Returns all the users from the database in JSON. Example:
[
{
"name": "Henry Bastos da Silva",
"username": "henry_bastos",
"age": 19
},
{
"name": "Jane Doe",
"username": "janeDoe",
"age": 38
}
]
- If it fails to return the users, it will return the error type
/errors/no-users-found
.
Returns a specific user from the database in JSON.
-
If the username is null or undefined, it will return
/errors/null-or-undefined
. -
If the user can not be found, it will return
/errors/user/user-not-found
.
Adds a user to the database. It requires the following structure:
{
"name": "Name and Surname",
"username": "username",
"age": 99
}
Successfull if all the requirements are pleased.
Requirements:
name
:- Not Unique: Do not need to be unique in the database.
- Not null/undefined: It can not be null nor undefined, otherwise it will return
/errors/null-or-undefined
. - String: Required as a String.
username
:- Unique: Required to be unique in the database, otherwise it will return
/errors/user/username-taken
. - Not null/undefined: It can not be null nor undefined, otherwise it will return
/errors/null-or-undefined
. - String: Required as a String.
- Unique: Required to be unique in the database, otherwise it will return
age
:- Not Unique: Do not need to be unique in the database.
- Not null/undefined: It can not be null nor undefined, otherwise it will return
/errors/null-or-undefined
. - Integer: Required as an Integer Number;
All the errors are returned following the standards of the document RFC7807.
They can be found at /errors/error-types.html
.
The current value is null or undefined.
Returned by:
{
"type": "/errors/null-or-undefined.html",
"title": "Value is Null or Undefined.",
"status": 400,
"detail": "Value is Null or Undefined.",
"instance": "*"
}
Username was already taken by another user.
Returned by
{
"type": "/errors/user/username-taken.html",
"title": "Username was already taken by another user.",
"status": 400,
"detail": "Username was already taken by another user.",
"instance": "/add-user"
}
No users could be found.
Returned by
{
"type": "/errors/no-users-found.html",
"title": "No users could be found.",
"status": 404,
"detail": "No users could be found.",
"instance": "/users"
}
User could not be found.
Returned by
{
"type": "/errors/user/user-not-found.html",
"title": "User could not be found.",
"status": 404,
"detail": "User could not be found.",
"instance": "/users/:username"
}