Backend for A to Z build week project
https://bw-a-to-z-experiences.herokuapp.com/
- Express: Fast, unopinionated, minimalist web framework for Node.js
- Bcryptjs: Allows you to store passwords securely in your database
- Jsonwebtoken: Generate and verify json web tokens to maintain a stateless api
- Knex: Knex.js is a "batteries included" SQL query builder for Postgres, MSSQL, MySQL, MariaDB, SQLite3, Oracle, and Amazon Redshift designed to be flexible, portable, and fun to use
- Sqlite3: Asynchronous, non-blocking SQLite3 bindings for Node.js.
- Morgan:
HTTP request logger middleware for Node.js
- Cors: CORS is a Node.js package for providing a Connect/Express middleware that can be used to enable CORS
- Helmet: Helmet helps you secure your Express apps by setting various HTTP headers
- Dotenv: Dotenv is a zero-dependency module that loads environment variables from a .env file
- Nodemon: nodemon is a tool that helps develop Node.js based applications by automatically restarting the node application when file changes in the directory are detected
(# <--- signifies comment) In your terminal run:
# Install dependencies
npm install
# Starts express server using nodemon
npm run server
Method Url: /api/register
HTTP method: [POST]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
name | type | required | description |
---|---|---|---|
username |
String | Yes | Must be unique |
password |
String | Yes | |
first_name |
String | Yes | |
last_name |
String | Yes | |
email |
String | No | |
city |
String | No |
example:
{
"username": "username"
"password": "password123",
"first_name": "First Name",
"last_name": "Last Name",
"email": "[email protected]",
"city": "NYC",
}
If you successfully register a user the endpoint will return an HTTP response with a status code
201
,message, and a token as below.
example:
{
"message": "Welcome user! You have been successfully registered!"
},
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI3IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTQ0MzM1NjUxLCJleHAiOjE1NzU4OTMyNTF9.uqd2OHBYkGQpwjLTPPiPWYkYOKlG7whQDFkk46xFXoX"
}
If there is a server or database error, the endpoint will return an HTTP response with a status code
500
and a body as below.
example:
{
"message": "Sorry, but something went wrong while registering"
}
Method Url: /api/login
HTTP method: [POST]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
name | type | required | description |
---|---|---|---|
username |
String | Yes | Must match a username in the database |
password |
String | Yes | Must match a password in the database corresponding to email above |
example:
{
"message": "Welcome, user!"
},
{
"username": "username"
"password": "password123",
}
If you successfully login, the endpoint will return an HTTP response with a status code
200
, message, and a token as below.
example:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MDwiaWF0IjoxNTQ0MzM1NjUxLCJleHAuOjE1NzU4OTMyNTF9.uqd2OHBYkGQpwjLTPPiPWYkYOKlG7whQDFkk46xGXnE",
}
If you fail to login, the endpoint will return an HTTP response with a status code
401
which indicates the username and/or password entered is not valid.
example:
{
message: "Wrong username or password. Try again."
}
If there is a server or database error, the endpoint will return an HTTP response with a status code
500
and a body as below.
example:
{
"message": "Sorry, but something went wrong while logging in"
}
Method Url: /api/users
HTTP method: [GET]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
Authorization |
String | Yes | JSON Web Token |
The endpoint will return an HTTP response with a status code 200 and a body as below.
example:
{
"id": 1,
"username": "username"
"first_name": "First Name",
"last_name": "Last Name",
"email": "[email protected]",
"city": "NYC"
}
If there is a server or database error, the endpoint will return an HTTP response with a status code
500
and a body as below.
example:
{
"message": "Error getting users"
}
Method Url: /api/users/:id
HTTP method: [GET]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
Authorization |
String | No | JSON Web Token |
If the user profile is found in the database, the endpoint will return an HTTP response with a status code 200 and a body as below.
example:
{
"id": 1,
"username": "username"
"first_name": "First Name",
"last_name": "Last Name",
"email": "[email protected]",
"city": "NYC"
}
If there is a server or database error, the endpoint will return an HTTP response with a status code
500
and a body as below.
example:
{
"message": "Sorry, but something went wrong while getting that user profile"
}
Method Url: /api/users/:id
HTTP method: [PUT]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
Authorization |
String | Yes | JSON Web Token |
name | type | required | description |
---|---|---|---|
id | Integer | Yes | ID of a specific seeker |
name | type | required | description |
---|---|---|---|
username |
String | No | |
first_name |
String | No | |
last_name |
String | No | |
email |
String | No | |
city |
String | No |
example:
{
"username": "username",
"name": "First Last",
"first_name": "First Name",
"last_name": "Last Name",
"email": "[email protected]",
"city": "NYC"
}
If a seeker with the specified ID in the URL parameters is updated successfully in the database, the endpoint will return an HTTP response with a status code
200
and a body as below.
example:
{
"message": `Your profile has been successfully updated`
}
If there is a server or database error, the endpoint will return an HTTP response with a status code
500
and a body as below.
example:
{
"message": "Sorry, but something went wrong while updating that profile"
}
Method Url: /api/users/:id
HTTP method: [DELETE]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
Authorization |
String | Yes | JSON Web Token |
name | type | required | description |
---|---|---|---|
id | Integer | Yes | ID of a specific seeker |
If a seeker with the specified ID in the URL parameters is deleted successfully in the database, the endpoint will return an HTTP response with a status code
200
and a body as below.
example:
{
"message": "1 user was successfully deleted"
}
If you send in invalid fields, the endpoint will return an HTTP response with a status code
500
and a body as below.
example:
{
"message": "Sorry, but something went wrong while deleting that user"
}
The user_id is reserved for the user who created the experience
Method Url: /api/users/:id/experiences_attending
HTTP method: [GET]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
Authorization |
String | Yes | JSON Web Token |
If the users experiences are found in the database, the endpoint will return an HTTP response with a status code 200 and a body as below.
example:
{
"user_id": 18,
"experience_id": 1,
"id": 1,
"title": "Arts",
"date": "date",
"location": "location",
"price": "$20",
"description": "Art lessons for all ages"
}
If there is a server or database error, the endpoint will return an HTTP response with a status code
500
and a body as below.
example:
{
"message": "Error getting users attending experiences"
}
The user_id is reserved for the user who created the experience
Method Url: /api/experiences/attend
HTTP method: [POST]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
Authorization |
String | Yes | JSON Web Token |
name | type | required | description |
---|---|---|---|
user_id |
String | Yes | Must be unique |
experience_id |
String | Yes |
example:
{
"user_id": 18,
"experience_id": 1
}
If the user is RSVPed for experience, the endpoint will return an HTTP response with a status code 200 and a body as below.
example:
{
"message": "You have successfully registered for this experience! See you there!"
}
If there is a server or database error, the endpoint will return an HTTP response with a status code
500
and a body as below.
example:
{
"message": "Sorry, there was an error registering for the experience"
}
*STILL BUGGY!*
Method Url: /api/users/:id/experiences_attending
HTTP method: [DELETE]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
Authorization |
String | Yes | JSON Web Token |
name | type | required | description |
---|---|---|---|
id | Integer | Yes | ID of a specific seeker |
If a user with the specified ID in the URL parameters is deleted successfully in the database, the endpoint will return an HTTP response with a status code
200
and a body as below.
example:
{
"message": "You are no longer attending this experience"
}
If you send in invalid fields, the endpoint will return an HTTP response with a status code
500
and a body as below.
example:
{
"message": "Sorry, but something went wrong while deleting that experience."
}
Method Url: /api/experiences
HTTP method: [GET]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
The endpoint will return an HTTP response with a status code 200 and a body as below.
example:
{
"experiences": [
{
"id": 1,
"user_id": 1,
"title": "Arts & crafts",
"date": "9/2/19",
"location": "Brooklyn, NY",
"price": "$20",
"description": "Art lessons for all ages"
}
}
If there is a server or database error, the endpoint will return an HTTP response with a status code
500
and a body as below.
example:
{
"message": "Sorry, Theres been an error getting experiences"
}
Method Url: /api/experiences/:id
HTTP method: [GET]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
Authorization |
String | No | JSON Web Token |
If the experience is found in the database, the endpoint will return an HTTP response with a status code 200 and a body as below.
example:
{
"id": 1,
"user_id": 1,
"title": "Arts & crafts",
"date": "9/2/19",
"location": "Brooklyn, NY",
"price": "$20",
"description": "Art lessons for all ages"
}
If there is a server or database error, the endpoint will return an HTTP response with a status code
500
and a body as below.
example:
{
"message": "Sorry, but something went wrong while getting that experience"
}
Method Url: /api/users/:id/host_experiences
HTTP method: [GET]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
Authorization |
String | Yes | JSON Web Token |
The endpoint will return an HTTP response with a status code 200 and a body as below.
example:
{
"id": 1,
"username": "new",
"first_name": "First Name",
"last_name": "Last Name",
"email": "[email protected]",
"city": "NYC"
"experiences": [
{
"id": 1,
"user_id": 1,
"title": "Arts & crafts",
"date": "9/2/19",
"location": "Brooklyn, NY",
"price": "$20",
"description": "Art lessons for all ages"
}
}
If there is a server or database error, the endpoint will return an HTTP response with a status code
500
and a body as below.
example:
{
"message": "Sorry, but something went wrong while getting that hosts experiences"
}
Method Url: /api/experiences
HTTP method: [POST]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
name | type | required | description |
---|---|---|---|
user_id |
Int | No | |
title |
String | Yes | Must be unique |
date |
String | Yes | |
location |
String | Yes | |
price |
String | No | |
description |
String | No |
example:
{
"user_id": 1,
"title": "Arts & crafts",
"date": "9/2/19",
"location": "Brooklyn, NY",
"price": "$20",
"description": "Art lessons for all ages"
}
If you successfully post an experience the endpoint will return an HTTP response with a status code
201
and a body as below.
example:
{
"id": 1,
"user_id": 1,
"title": "Arts & crafts",
"date": "9/2/19",
"location": "Brooklyn, NY",
"price": "$20",
"description": "Art lessons for all ages"
}
If the user has not provided a title, date, or location, the endpoint will return an HTTP response with a status code
404
and a body as below.
example:
{
"message": "Sorry, all new experiences require a title, date, and location."
}
If there is a server or database error, the endpoint will return an HTTP response with a status code
500
and a body as below.
example:
{
"message": "Sorry, but something went wrong while added the experience"
}
Method Url: /api/experiences/:id
HTTP method: [PUT]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
Authorization |
String | Yes | JSON Web Token |
name | type | required | description |
---|---|---|---|
id | Integer | Yes | ID of a specific seeker |
name | type | required | description |
---|---|---|---|
user_id |
Int | No | |
title |
String | No | Must be unique |
date |
String | No | |
location |
String | No | |
price |
String | No | |
description |
String | No |
example:
{
"user_id": 1,
"title": "Arts & crafts",
"date": "9/2/19",
"location": "Brooklyn, NY",
"price": "$20",
"description": "Art lessons for all ages"
}
If an experience with the specified ID in the URL parameters is updated successfully in the database, the endpoint will return an HTTP response with a status code
200
and a body as below.
example:
{ message: "Your experience has been successfully update" }
{
"user_id": 1,
"title": "Arts & crafts",
"date": "9/2/19",
"location": "Brooklyn, NY",
"price": "$20",
"description": "Art lessons for all ages"
}
If there is a server or database error, the endpoint will return an HTTP response with a status code
500
and a body as below.
example:
{
"message": "Sorry, but something went wrong while updating that experience"
}
Method Url: /api/experiences/:id
HTTP method: [DELETE]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
Authorization |
String | Yes | JSON Web Token |
name | type | required | description |
---|---|---|---|
id | Integer | Yes | ID of a specific seeker |
If an experience with the specified ID in the URL parameters is deleted successfully in the database, the endpoint will return an HTTP response with a status code
200
and a body as below.
example:
{
"message": "1 experience was successfully deleted"
}
If you send in invalid fields, the endpoint will return an HTTP response with a status code
500
and a body as below.
example:
{
"message": "Sorry, but something went wrong while deleting that experience"
}