Giter Site home page Giter Site logo

api-rest-pets-collection's Introduction

API Rest Pet Collection

Tiny Rest API for teaching purposes. Express, Typescript and Prisma. Try this service on this Live Demo

Prerequisites:

Configure your environment variables on .env file:

DATABASE_URL="mysql://root:root@localhost/test"
JWT_SECRET="secret"

Install dependencies with:

npm install

Push DB changes with:

npx prisma db push

Usage:

The app counts with the following endpoints:

GET /api/v1/info

Returns information about the app.

GET /api/v1/ping

Returns 200 code if the app is running.


POST /api/v1/auth/login

Returns a JWT token if the credentials are correct.

Example request:

Method: POST

Endpoint: /api/v1/auth/login

Body:

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

Example succesfully response:

Status: 200

Body:

{
  "token": "<jwt_token>"
}

POST /api/v1/auth/register

Returns the new user if email doesnt exists.

Example request:

Method: POST

Endpoint: /api/v1/auth/register

Body:

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

Example succesfully response:

Status: 201

Body:

{
  "id": 1,
  "email": "[email protected]"
}

GET /api/v1/pets

Returns all user's pets. Requires Bearer Token at Authorization Header

Example request:

Method: GET

Endpoint: /api/v1/pets

Example succesfully response:

Status: 200

Body:

[
  {
    "id": 1,
    "name": "Cheems",
    "type": "Dog",
    "birth": "2020-01-01T00:00:00.000Z",
    "photo": "someUrl",
    "userId": 1
  }
]

GET /api/v1/pets/:id

Return a pet by id. Requires Bearer Token at Authorization Header

Example request:

Method: GET

Endpoint: /api/v1/pets/1

Example succesfully response:

Status: 200

Body:

{
  "id": 1,
  "name": "Cheems",
  "type": "Dog",
  "birth": "2020-01-01T00:00:00.000Z",
  "photo": "someUrl",
  "userId": 1
}

POST /api/v1/pets

Create a new pet for logged user. Requires Bearer Token at Authorization Header

Example request:

Method: POST

Endpoint: /api/v1/pets

Body:

{
  "name": "Cheems",
  "type": "Dog",
  "birth": "2020-01-01T00:00:00.000Z",
  "photo": "someUrl"
}

Example successfully response:

Status: 201

Body:

{
  "id": 1,
  "name": "Cheems",
  "type": "Dog",
  "birth": "2020-01-01T00:00:00.000Z",
  "photo": "someUrl",
  "userId": 1
}

PUT /api/v1/pets/:id

Update a pet by id. Requires Bearer Token at Authorization Header

Example request:

Method: PUT

Endpoint: /api/v1/pets/1

Body:

{
  "name": "NotCheems",
  "type": "Cat"
}

Example successfully response: Status: 204

DELETE /api/v1/pets/:id

Delete a pet by id. Requires Bearer Token at Authorization Header

Example request:

Method: DELETE

Endpoint: /api/v1/pets/1

Example successfully response:

Status: 204

api-rest-pets-collection's People

Contributors

borisbelmar avatar

Stargazers

Frank Moisés avatar Diana Cerda 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.