/byob

Primary LanguageJavaScript

Build Your Own Backend

Robbie Greiner & Alex Banister

Introduction

This application builds an entire backend database containing construction project and employee data

Built With

* JavaScript
* Node
* Express
* Knex
* PostgreSQL
* JWT Tokens
* HTML
* CSS
* Chai/Mocha

API Documentation

Authentication

This API requires a JSON Web Token (JWT) in order to modify any of the data in the database. Request a token through the following endpoint:

/api/v1/auth

The request body for the token must must include the properties appName and email

This token must be included when making requests with the following methods:

    POST
    DELETE
    PUT
    PATCH

The token can be included in any of the following locations:

  • Request Body: Add a key value pair for token in the body.

  • Authorization Header: Add an Authorization key with a token for the value.

  • Query Parameter: Use '?token=' as a query parameter to the request path with the token as value.

Authorization

Users will be granted access to modify data if they have an email address that ends with '@turing.io'

Resources

NOTES

  • All API requests will be returned JSON format.

HTTP Status Codes

All responses will be returned with one of the following HTTP status codes:

  • 200 OK The request was successful
  • 400 Bad Request There was a problem with the request due to client error
  • 401 Unauthorized User is unauthenticated and does not have the necessary credentials
  • 403 Forbidden The user might not have the necessary permissions for a resource or may need an account of some sort
  • 404 Not found The resource could not be found
  • 405 Method not allowed The resource does not support the request method
  • 500 Internal Server Error Unexpected error was encountered on server side

Endpoints

Authentication for JSON Web Token (JWT)

  • POST /api/v1/auth

Example request:

{
   "appName": "byob",
   "email": "robbie@turing.io",

}

Example response:

"eyJhbGciOiJIUzI1NiIsInR5cCI6IpkXVCJ9.eyJhcHBOYW1lIjoiYnlvYiIsImVtYWlsIjoicm9iYmllQHR1cmluZy5pbyJ9.xhqE8SYBJP7V2zif9UgrIVVuyqyNDiRRsQ8asrt7ODA"

Projects

GET /api/v1/projects

Example request:

  • No body required/accepted

Example response:

[
  {
    "id": 65,
    "name": "United Airlines Remodel",
    "location": "Denver",
    "union": true,
    "public": true
  },
  {
    "id": 66,
    "name": "Coors Field West Mezzanine",
    "location": "Denver",
    "union": true,
    "public": true
  },
  {
    "id": 67,
    "name": "Denver Brewing Company Tank 7",
    "location": "Denver",
    "union": false,
    "public": false
  }
]
  • This endpoint accepts query parameters /api/v1/projects/?name=United Airlines Remodel response:
    [
      {
        "id": 65,
        "name": "United Airlines Remodel",
        "location": "Denver",
        "union": true,
        "public": true
      }
    ]
    
    Accepted query parameters are name and location

GET /api/v1/projects/:projectId/employees

Example request:

  • No body required/accepted

Example response:

[
  {
    "id": 62,
    "name": "Robbie Greiner",
    "position": "Foreman",
    "email": "robbie@gcbuilders.net",
    "phone": "303-123-4567",
    "project_id": 65,
    "employee_id": 62
  },
  {
    "id": 65,
    "name": "Alex Berg",
    "position": "Foreman",
    "email": "alex@gcbuilders.net",
    "phone": "303-123-4570",
    "project_id": 65,
    "employee_id": 65
  },
  {
    "id": 76,
    "name": "Ron Swanson",
    "position": "Carpenter",
    "email": "ron@gcbuilders.net",
    "phone": "303-123-4581",
    "project_id": 65,
    "employee_id": 76
  }
]

GET /api/v1/projects/:projectId/

Example request:

  • No body required/accepted

Example response:

{
  "id": 76,
  "name": "Turing School",
  "location": "Denver",
  "union": false,
  "public": false
}

POST /api/v1/projects

Example request:

{
  "name": "Turing School",
  "location": "Denver",
  "union": false,
  "public": false
}

Example response:

{
  "id": 95
}

POST /api/v1/projects/:projectId/employees/:employeeId

Example request:

  • No request body

Example response:

  • No response body. Status code 201

DELETE /api/v1/projects/:projectId

Example request:

  • No request body

Example response:

  • No response body. Status code 204

PATCH /api/v1/projects/:projectId

Example request:

{
  "name": "Turing School",
  "location": "Denver",
  "union": false,
  "public": false
}
  • Request body only requires the key value pairs being changed

Example response:

  • No response body. Status code 204

Employees

GET /api/v1/employees

Example request:

  • No body required/accepted

Example response:

[
  {
    "id": 62,
    "name": "Robbie Greiner",
    "position": "Foreman",
    "email": "robbie@gcbuilders.net",
    "phone": "303-123-4567"
  },
  {
    "id": 63,
    "name": "Bill Smith",
    "position": "Foreman",
    "email": "bill@gcbuilders.net",
    "phone": "303-123-4568"
  },
  {
    "id": 64,
    "name": "Todd Gak",
    "position": "Foreman",
    "email": "todd@gcbuilders.net",
    "phone": "303-123-4569"
  }
]
- This endpoint accepts query parameters
  <code>/api/v1/projects/?name=Todd Gak</code>
  **response:**
  ```
  {
    "id": 64,
    "name": "Todd Gak",
    "position": "Foreman",
    "email": "todd@gcbuilders.net",
    "phone": "303-123-4569"
  }
  ```
  Accepted query parameters are <code>name</code>, <code>position</code>, <code>email</code>, and  <code>phone</code>

GET /api/v1/employees/:employeeId/

Example request:

  • No body required/accepted

Example response:

{
  "id": 64,
  "name": "Todd Gak",
  "position": "Foreman",
  "email": "todd@gcbuilders.net",
  "phone": "303-123-4569"
}

GET /api/v1/employees/:employeeId/projects

Example request:

  • No body required/accepted

Example response:

[
  {
    "id": 77,
    "name": "CU Denver Student Activities",
    "location": "Denver",
    "union": true,
    "public": true,
    "project_id": 77,
    "employee_id": 75
  },
  {
    "id": 89,
    "name": "State Farm Office",
    "location": "Golden",
    "union": false,
    "public": false,
    "project_id": 89,
    "employee_id": 75
  }
]

POST /api/v1/employees

Example request:

{
  "name": "Malcolm Reynolds",
  "position": "Captain",
  "email": "mal@gcbuilders.net",
  "phone": "303-123-4569"
}

Example response:

{
  "id": 77
}

DELETE /api/v1/employees/:employeeId

Example request:

  • No request body

Example response:

  • No response body. Status code 204

DELETE /api/v1/projects/:projectId/employees/:employeeId

Example request:

  • No request body

Example response:

  • No response body. Status code 204

PATCH /api/v1/employees/:employeeId

Example request:

{
  "name": "Malcolm Reynolds",
  "position": "Captain",
  "email": "mal@gcbuilders.net",
  "phone": "303-123-4569"
}
  • Request body only requires the key value pairs being changed

Example response:

  • No response body. Status code 204