An API develop for practicing concepts of REST API. It's a game API, which we can register, read, update and delete games from database.
- Javascript
- Nodejs
- JWT
- Express
- MongoDB
- Mongoose
Register a new user in database
Parameters: None
Authorization: None
{
"nickname": "pedro",
"email":"pedro@example.com",
"password": "password"
}
status 201 CREATED
{
"user": {
"nickname": "pedro",
"email": "pedro@example.com",
"_id": "62b3463e206b9ca05057cdff",
"__v": 0
},
"message": "Usuário criado"
}
status 400 Bad Request
{
"error": "User already exists OR error in data body"
}
Authenticate user in API
Parameters: None
Authorization: None
{
"nickname": "pedro",
"password": "password"
}
status 200 OK
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cC...",
"user": {
"_id": "62a2959b040d026feedf4807",
"nickname": "pedro",
"email": "pedro@example.com",
"__v": 0
}
}
status 400 Bad Request
{
"error": "error in data body"
}
```json
status 404 Not Found
{
"error": "User not found OR incorrect password"
}
Register a game in database
Parameters: None
Authorization: Yes
access-token: "JWT token"
{
"name": "God of War",
"price": 90,
"year": 2018
}
status 201 CREATED
{
"_id": "629d4d633ed767f59edf4c82",
"name": "God of War",
"year": 2018,
"price": 90,
"__v": 0
}
status 400 Bad request
{
"error": "Error in body data OR game already exists"
}
status 401 Unauthorized
{
"error": "invalid token OR restricted access"
}
Return all games in database
Parameters: None
Authorization: Yes
access-token: "JWT token"
status 200 OK
[
{
"_id": "629d4d633ed767f59edf4c82",
"name": "FIFA 22",
"year": 2021,
"price": 85,
"__v": 0
},
{
"_id": "629e9109b8bd0087ed2e50fd",
"name": "Skyrim",
"year": 2011,
"price": 50,
"__v": 0
},
]
status 401 Unauthorized
{
"error": "invalid token OR restricted access"
}
Return a specific game by ID
Parameters: Yes
Authorization: Yes
access-token: "JWT token"
status 200 OK
{
"_id": "629d4d633ed767f59edf4c82",
"name": "FIFA 22",
"year": 2021,
"price": 85,
"__v": 0
}
status 401 Unauthorized
{
"error": "invalid token OR restricted access"
}
status 404 Not Found
{
"error": "Game not found"
}
Update a specific game by ID
Parameters: Yes
Authorization: Yes
access-token: "JWT token"
status 200 OK
{
"_id": "629e95b6e65d912a7be6a932",
"name": "PES 2020",
"year": 2022,
"price": 0,
"__v": 0
}
status 400 Bad Request
{
"error": "ID parameter is required OR error in data body"
}
status 401 Unauthorized
{
"error": "invalid token OR restricted access"
}
status 404 Not Found
{
"error": "Game not found"
}
Delete a specific game by ID
Parameters: Yes
Authorization: Yes
access-token: "JWT token"
{
"name": "God of War",
"price": 90,
"year": 2018
}
status 200 OK
{
"data": {
"_id": "629e95b6e65d912a7be6a932",
"name": "PES 2020",
"year": 2022,
"price": 0,
"__v": 0
},
"message": "Game removido"
}
status 400 Bad Request
{
"error": "ID parameter is required"
}
status 401 Unauthorized
{
"error": "invalid token OR restricted access"
}
status 404 Not Found
{
"error": "Game not found"
}
npm install
npm run dev