Git Product home page Git Product logo

api-games's Introduction

API para Games

Descrição

Exemplo de API RESTful para gestão de games.
(Está API não foi feita para ter uma utilidade real, o obejtivo era entender o processo de criação e consumo de uma API.)

EndPoints

  • POST /auth

Responsável por gerar Token de autenticação.

Parâmetros

email: email cadastrado no sistema.
password: senha cadastrada no sistema, referente ao email.

{
    "email": "[email protected]",
    "password": "senha123"
}

Respostas

200 OK!
{
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJmZWxpcGVmY2xhcmlhbm8wNEBnbWFpbC5jb20iLCJpYXQiOjE2NTYyOTM3MjMsImV4cCI6MTY1NjQ2NjUyM30.E37LjpU7mPTMMmYK-9eLyjaPQ2MbFSvLbBLWWR3rfnQ",
    "_links": [
        {
            "href": "http://localhost:8080/games",
            "method": "GET",
            "ref": "get_games"
        },
        {
            "href": "http://localhost:8080/game",
            "method": "POST",
            "ref": "create_game"
        }
    ]
}
400 - Bad Request.
{
    "err": "Email inválido ou ausente."
}
{
    "err": "Senha ausente."
}
401 - Unauthorized.
{
    "err": "Credenciais inválidas."
}
404 - Not Found.
{
    "err": "O email enviado não exite na base de dados."
}
500 - Internal Server Error.
{
    "err": "Erro interno."
}

  • GET /games

Responsável por retornar todos os games do database

Parâmetros

Nenhum

Respostas

200 - OK
{
    "games": [
        {
            "id": 1,
            "title": "Minecraft",
            "year": "2012",
            "price": 30,
            "createdAt": "2022-06-22T23:41:56.000Z",
            "updatedAt": "2022-06-22T23:41:56.000Z"
        },
        {
            "id": 2,
            "title": "Sea of Thieves",
            "year": "2018",
            "price": 50.9,
            "createdAt": "2022-06-22T23:41:56.000Z",
            "updatedAt": "2022-06-23T21:54:52.000Z"
        },
        {
            "id": 3,
            "title": "Call of Dutty MW",
            "year": "2019",
            "price": 37.84,
            "createdAt": "2022-06-22T23:41:56.000Z",
            "updatedAt": "2022-06-27T16:42:25.000Z"
        },
        {
            "id": 4,
            "title": "Transformice",
            "year": "2010",
            "price": 0,
            "createdAt": "2022-06-23T16:27:06.000Z",
            "updatedAt": "2022-06-23T16:27:06.000Z"
        },
        {
            "id": 7,
            "title": "Sonic",
            "year": "1991",
            "price": 10.75,
            "createdAt": "2022-06-23T16:33:58.000Z",
            "updatedAt": "2022-06-23T17:24:29.000Z"
        },
        {
            "id": 9,
            "title": "Ben 10 - Protector of Earth",
            "year": "2007",
            "price": 12,
            "createdAt": "2022-06-24T00:48:31.000Z",
            "updatedAt": "2022-06-24T00:48:31.000Z"
        },
        {
            "id": 10,
            "title": "Rocket League",
            "year": "2015",
            "price": 0,
            "createdAt": "2022-06-24T00:52:10.000Z",
            "updatedAt": "2022-06-24T20:27:57.000Z"
        }
    ],
    "_links": [
        {
            "href": "http://localhost:8080/game",
            "method": "POST",
            "ref": "create_game"
        }
    ]
}
404 - Not Found.
{
    "err": "Não há games cadastrados."
}

  • GET /game/:id

Responsável por retornar dados de um game específico.

Parametros

:id - id do game que deseja ver os dados.

Exemplos

/game/4
/game/25

Respostas

200 OK!
{
    "game": {
        "id": 3,
        "title": "Call of Dutty MW",
        "year": "2019",
        "price": 37.84,
        "createdAt": "2022-06-22T23:41:56.000Z",
        "updatedAt": "2022-06-27T16:42:25.000Z"
    },
    "_links": [
        {
            "href": "http://localhost:8080/games",
            "method": "GET",
            "ref": "get_games"
        },
        {
            "href": "http://localhost:8080/game/3",
            "method": "DELETE",
            "ref": "delete_game"
        },
        {
            "href": "http://localhost:8080/game/3",
            "method": "PUT",
            "ref": "edit_game"
        }
    ]
}
400 Invalid request.
{
    "err": "ID inválido"
}
404 - Not Found.
{
"err": "Game não encontrado."
}

  • POST /game

Responsável por cadastrar um game no database.

Parametros

title: Título do game
year: Ano de lançamento do game
price: Preço do jogo

{
    "title": "League of Legends",
    "year": 2009,
    "price": 0
}

Respostas

200 OK!
{
    "_links": [
        {
            "href": "http://localhost:8080/games",
            "method": "GET",
            "ref": "get_games"
        },
        {
            "href": "http://localhost:8080/game",
            "method": "POST",
            "ref": "create_game"
        }
    ]
}
400 Bad Request.
{
    "err": "Título inválido ou ausente."
}
{
    "err": "Ano de lançamento inválido ou ausente."
}
{
    "err": "Preço inválido ou ausente."
}
500 Internal Server Error.
{
    "err": "Erro interno."
}

  • DELETE /game/:id

Responsável por deletar um game específico do database.

Parametros

:id - id do game que deseja deletar.

Exemplos

/game/4
/game/25

Respostas

200 OK!
{
    "_links": [
        {
            "href": "http://localhost:8080/games",
            "method": "GET",
            "ref": "get_games"
        },
        {
            "href": "http://localhost:8080/game",
            "method": "POST",
            "ref": "create_game"
        }
    ]
}
400 Bad Request.
{
    "err": "ID inválido."
}
500 Internal Server Error.
{
    "err": "Erro interno."
}

  • PUT /game/:id

Responsável por editar games no database.

Parametros

:id - id do game que deseja editar.

title: Título do game
year: Ano de lançamento do game
price: Preço do jogo

Exemplos

/game/4
/game/25

Respostas

200 OK!
{
    "_links": [
        {
            "href": "http://localhost:8080/games",
            "method": "GET",
            "ref": "get_games"
        },
        {
            "href": "http://localhost:8080/game/12",
            "method": "GET",
            "ref": "get_game"
        },
        {
            "href": "http://localhost:8080/game",
            "method": "POST",
            "ref": "create_game"
        }
    ]
}
400 Bad Request.
{
    "err": "ID inválido."
}
{
    "err": "Ano de lançamento inválido."
}
{
    "err": "Preço inválido."
}
404 Not Found.
{
    "err": "Game não encontrado."
}
500 Internal Server Erro.
{
    "err": "Erro interno."
}

api-games's People

Contributors

fuckners avatar

Stargazers

 avatar

Watchers

 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.