This application constructs an entire backend database and api using Brewery data from the Brewery DB API. This data is imported into a local .json file which is then used to seed the local database. The application also supports jwt Tokens, in which the client must request a token with a valid email address before they are allowed to make any modifications to the database.
* HTML
* CSS
* JavaScript
* Knex
* Express
* PostgreSQL
* JWT Tokens
* Chai/Mocha
This API requires a JWT Token in order to modify any of the data in the BYOB database. A token must be requested through the following endpoint:
/api/v1/authenticate
The request body for the token must must include the properties appName and email
Example body for Token request:
{
"appName": "byob",
"email": "[email protected]"
}
Example body for Token response:
{
"token": "eyJhbGciOiJIUzI1NiIsIeR5cCI6IkpXVCJ9.eyJlbWFpbCI6Im5pY2tAdHVyaW5nLmlvcCIsImFwcE5hbWUiOiJieW9iIiwiYWRtaW4iOmZIbHNlLCJpYXQiOjE1MDgwNDQ0MzMsImV4cCP6MTUwODIxNzIzM30.813d0w87z2x4EZUNdEbUcamDysHxM0bI31cm239algI",
"adminVerification": true
}
This token must be included when making requests against the following endpoints:
POST
DELETE
PUT
PATCH
The token may be included in any of the following 3 methods:
-
Request Body: Include the token in a property called 'token' in the body of the request.
-
Authorization Header: Add an 'Authorization' header to the request with the token as the value.
-
Query Parameter: Include an '?token=' query parameter to the request path with the token as value.
The JWT Token issued to the client is 'stamped' with either admin access (ability to call API endpoints in BYOB database which modifies data), or grants access to only GET request endpoints with read-only access.
This validation is based on detection of an email address with '@turing.io'
NOTES
- The response format for all API requests is JSON format.
- Errors will be returned also as JSON objects with an 'error' property.
- The value of 'error' is the error message as a string.
Each response will be returned with one of the following HTTP status codes:
See documentation of individual endpoints for possible status code return values
200
OK
The request was successful201
Created
The request has been fulfilled and has resulted in one or more new resources being created204
No Content
The server has successfully fulfilled the request and that there is no additional content to send in the response payload body400
Bad Request
There was a problem with the request (security, malformed, data validation, etc.)403
Forbidden
The credentials provided do not have permission to access the requested resource404
Not found
An attempt was made to access a resource that does not exist in the API422
Unprocessable Entity
The server understands the content type of the request entity, but was unable to process the contained instructions500
Server Error
An error on the server occurred