Giter VIP home page Giter VIP logo

pokemonapi's Introduction

Pokemon API ๐ŸŒธ

The Pokemon Choose You!

This API was cloned from Oli's doggy API to create our Pokemon Project. ๐Ÿถ

Run locally

  1. Clone this repo
  2. npm install all dependencies
  3. Setup environment variables (see below)
  4. npm run dev to start the dev server

Docs

Current version is v1, so make sure that is in all URLs. The base URL is https://dogs-rest.herokuapp.com/v1/.

Users

Path Method Body Example response
/users/:id GET n/a { "id": 1, "email": "[email protected]", "name": "oli" }
/users/ POST { "email: "[email protected]", "name": "oli", "password": "123" } { "id": 1, "email": "[email protected]", "name": "oli", "access_token": "ey5a..." }
/users/login POST { "email": "[email protected]", "password": "123" } { "id": 1, "access_token": "ey5a..." }

Dogs

Path Method Body Example response
/dogs/ GET n/a [{ "id": 1, "name": "Luna", "breed": "Cocker Spaniel", "owner": 1 }]
/dogs/:id GET n/a { "id": 1, "name": "Luna", "breed": "Cocker Spaniel", "owner": 1 }
/dogs/ POST { "name": "Pongo", "breed": "Dalmation" } { "id": 2, "name": "Pongo", "breed": "Dalmation", "owner": 1 }
/dogs/:id PUT { "name": "Pongo2" } { "id": 2, "name": "Pongo2", "breed": "Dalmation", "owner": 1 }
/dogs/:id DELETE n/a n/a

Authentication

All non-GET /dogs endpoints require a bearer token sent in the authorization header. For example Bearer ey6sjbnafdn.asbdabkjn. The token should be the JWT returned from the POST /users and POST /users/login endpoints.

Updating or deleting a dog also requires that the authenticated user be the owner of that dog (i.e. the dog's owner ID matches the user's id).

Schema

Users

Column Type Constraints
id SERIAL PRIMARY KEY
email VARCHAR(255) NOT NULL
name VARCHAR(255)
password VARCHAR(255)

Dogs

Column Type Constraints
id SERIAL PRIMARY KEY
name VARCHAR(255)
breed VARCHAR(255)
owner INTEGER REFERENCES users(id)

Postman

Postman is a useful tool for developing against an API. You can import my collection which contains pre-built requests for each endpoint. Save the JSON below and then go to File > Import... in Postman to import the JSON file.

Click to reveal the JSON
{
  "info": {
    "_postman_id": "b0655c9a-096b-4575-b15c-aecedcef8f1d",
    "name": "Dogs REST API",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "Create user",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"email\": \"[email protected]\",\n\t\"password\": \"123\",\n\t\"name\": \"oli\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://dogs-rest.herokuapp.com/v1/users",
          "protocol": "https",
          "host": ["dogs-rest", "herokuapp", "com"],
          "path": ["v1", "users"]
        }
      },
      "response": []
    },
    {
      "name": "Log in",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "type": "text",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"email\": \"[email protected]\",\n\t\"breed\": \"password123\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://dogs-rest.herokuapp.com/v1/users/login",
          "protocol": "https",
          "host": ["dogs-rest", "herokuapp", "com"],
          "path": ["v1", "users", "login"]
        }
      },
      "response": []
    },
    {
      "name": "Create dog",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "type": "text",
            "value": "application/json"
          },
          {
            "key": "Authorization",
            "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoxNTg2NzAxOTczNzE3LCJpYXQiOjE1ODY3MDMxMTYsImV4cCI6MTU4NjcwNjcxNn0.aM32hs0aFB9FzeBQI7IW0m0GLEVoMBKo_Qhkh8ulOOs",
            "type": "text",
            "disabled": true
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"name\": \"Pongo\",\n\t\"breed\": \"Dalmation\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://dogs-rest.herokuapp.com/v1/dogs",
          "protocol": "https",
          "host": ["dogs-rest", "herokuapp", "com"],
          "path": ["v1", "dogs"]
        }
      },
      "response": []
    },
    {
      "name": "Get all dogs",
      "protocolProfileBehavior": {
        "disableBodyPruning": true
      },
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "type": "text",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://dogs-rest.herokuapp.com/v1/dogs",
          "protocol": "https",
          "host": ["dogs-rest", "herokuapp", "com"],
          "path": ["v1", "dogs"]
        }
      },
      "response": []
    },
    {
      "name": "Get dog",
      "protocolProfileBehavior": {
        "disableBodyPruning": true
      },
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "type": "text",
            "value": "application/json"
          },
          {
            "key": "Authorization",
            "type": "text",
            "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoxNTg2NzAxOTczNzE3LCJpYXQiOjE1ODY3MDMxMTYsImV4cCI6MTU4NjcwNjcxNn0.aM32hs0aFB9FzeBQI7IW0m0GLEVoMBKo_Qhkh8ulOOs",
            "disabled": true
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://dogs-rest.herokuapp.com/v1/dogs/1",
          "protocol": "https",
          "host": ["dogs-rest", "herokuapp", "com"],
          "path": ["v1", "dogs", "1"]
        }
      },
      "response": []
    },
    {
      "name": "Delete dog",
      "request": {
        "method": "DELETE",
        "header": [
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "type": "text",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://dogs-rest.herokuapp.com/v1/dogs/3",
          "protocol": "https",
          "host": ["dogs-rest", "herokuapp", "com"],
          "path": ["v1", "dogs", "3"]
        }
      },
      "response": []
    },
    {
      "name": "Update dog",
      "request": {
        "method": "PUT",
        "header": [
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "type": "text",
            "value": "application/json"
          },
          {
            "key": "Authorization",
            "type": "text",
            "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoxNTg2NzAxOTczNzE3LCJpYXQiOjE1ODY3MDMxMTYsImV4cCI6MTU4NjcwNjcxNn0.aM32hs0aFB9FzeBQI7IW0m0GLEVoMBKo_Qhkh8ulOOs"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"name\": \"Pongo4\",\n\t\"breed\": \"Dalmation\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://dogs-rest.herokuapp.com/v1/dogs/3",
          "protocol": "https",
          "host": ["dogs-rest", "herokuapp", "com"],
          "path": ["v1", "dogs", "3"]
        }
      },
      "response": []
    }
  ],
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoxLCJpYXQiOjE1ODc1NTI1MjQsImV4cCI6MTU4NzU1NjEyNH0.cu-53kfrS5WDhMkccyiAxnf0q691sl4KLvnTf0zCo6E",
        "type": "string"
      }
    ]
  },
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "id": "41836924-9670-43ee-b1c0-2b51e8231746",
        "type": "text/javascript",
        "exec": [""]
      }
    },
    {
      "listen": "test",
      "script": {
        "id": "a8e31be7-dfc2-45c6-8f30-c2150f557be9",
        "type": "text/javascript",
        "exec": [""]
      }
    }
  ],
  "protocolProfileBehavior": {}
}

pokemonapi's People

Contributors

chloeh24 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.