Code Monkey home page Code Monkey logo

api-games's Introduction

Games API

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.

This API was developed in:

  • Javascript
  • Nodejs
  • JWT
  • Express
  • MongoDB
  • Mongoose

User Endpoints

POST /register

Register a new user in database

Parameters: None

Authorization: None

Body

{
 "nickname": "pedro",
 "email":"[email protected]",
 "password": "password"
}

Response

status 201 CREATED
{
 "user": {
  "nickname": "pedro",
  "email": "[email protected]",
  "_id": "62b3463e206b9ca05057cdff",
  "__v": 0
 },
 "message": "Usuário criado"
}
status 400 Bad Request
{
 "error": "User already exists OR error in data body"
}

POST /auth

Authenticate user in API

Parameters: None

Authorization: None

Body

{
 "nickname": "pedro",
 "password": "password"
}

Response

status 200 OK
{
 "token": "eyJhbGciOiJIUzI1NiIsInR5cC...",
 "user": {
  "_id": "62a2959b040d026feedf4807",
  "nickname": "pedro",
  "email": "[email protected]",
  "__v": 0
 }
}
status 400 Bad Request
{
 "error": "error in data body"
}
```json
status 404 Not Found
{
 "error": "User not found OR incorrect password"
}

Game Endpoints

POST /game

Register a game in database

Parameters: None

Authorization: Yes

Headers

access-token: "JWT token"

Body

 {
  "name": "God of War",
  "price": 90,
  "year": 2018
 }

Response

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"
}

GET /games

Return all games in database

Parameters: None

Authorization: Yes

Headers

access-token: "JWT token"

Response

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"
}

GET /game/:id

Return a specific game by ID

Parameters: Yes

Authorization: Yes

Headers

access-token: "JWT token"

Response

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"
}

PUT /game/:id

Update a specific game by ID

Parameters: Yes

Authorization: Yes

Headers

access-token: "JWT token"

Response

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 /game/:id

Delete a specific game by ID

Parameters: Yes

Authorization: Yes

Headers

access-token: "JWT token"

Body

 {
  "name": "God of War",
  "price": 90,
  "year": 2018
 }

Response

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"
}

Installation

npm install

Running

npm run dev

api-games's People

Contributors

pedrohercules avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.