This repository holds all backend files for the FoodieFun application. You can find it deployed here.
- Node.js
- Express
- Helmet & Cors
- Knex
- SQLite3 (development)
- MySQL (production)
- Jest & Supertest
Fork/Clone the repository. In the same directory as the package.json, run:
npm install
This will install all packages. To start the server:
npm start
To start the server using nodemon:
npm run dev
To test the repository:
npm test
username: admin
password: password
users
{
"id": 1, // Integer [Primary key]
"username": "admin", // String [Required, Unique]
"password": "password" // String [Required]
}
Method Url: https://foodiefun-api.herokuapp.com/api/auth/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 |
example:
{
"username": "admin",
"password": "password"
}
If you successfully register a user the endpoint will return an HTTP response with a status code
201
and a body as below.
{
"message": "Created user",
"user": {
"id": 1,
"username": "admin"
}
}
If you send in invalid/incomplete, the endpoint will return an HTTP response with a status code
400
and a body as below.
{
"message": "Required parameter missing"
}
If the username already exists, the endpoint will return an HTTP response with a status code
422
and a body as below.
{
"message": "Username already exists"
}
Method Url: https://foodiefun-api.herokuapp.com/api/auth/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 username |
example:
{
"username": "admin",
"password": "password"
}
If you successfully login, the endpoint will return an HTTP response with a status code
200
and a body as below.
{
"message": "You have been identified successfuly",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImRhdmlkIiwiaWF0IjoxNTY0Mzk3ODYyLCJleHAiOjE1NjQ2NTcwNjJ9._wanT3asvdrD-O4qFJhCqCDBFZbDnLFNVETZPaQJ52M"
}
If you send in invalid fields, the endpoint will return an HTTP response with a status code
400
and a body as below.
{
"message": "Missing required credentials"
}
If you send in a username that does not match one in the database, the endpoint will return an HTTP response with a status code
401
and a body as below.
{
"message": "Wrong credentials"
}
Method URL https://foodiefun-api.herokuapp.com/api/reviews
HTTP method: [GET]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
Authorization |
String | Yes | JWT authorization token |
If you successfully return the reviews for the user, the endpoint will return an HTTP response with a status code
200
and a body as below.
example
[
{
"id": 1,
"userId": 1,
"menuItem": "Carne Asada Tacos",
"restaurantType": "Mexican",
"comments": "The meat was a little dry and service was slow, but tasted good overall!",
"foodRating": 4,
"waitTime": 30,
"price": 6.4,
"photoOfOrder": "https://www.eatingonadime.com/wp-content/uploads/2018/05/easy-street-tacos.jpg",
"dateOfVisit": "2019-05-06",
"restaurantName": "Escorpion"
}
]
If you are not logged in or your session has expired, the endpoint will return code
500
and a body as follows:
"message": "You are not authorized to perform that operation"
You can pass filters as queries in the request using the name of the data fields
example:
Method URL https://foodiefun-api.herokuapp.com/api/reviews?restaurantType=Mexican
HTTP method: [GET]
Will return all the created reviews by the user with the restaurantType
as Mexican
.
Method URL https://foodiefun-api.herokuapp.com/api/reviews
HTTP method: [POST]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
Authorization |
String | Yes | JWT authorization token |
name | type | required | description |
---|---|---|---|
menuItem |
String | Yes | |
restaurantType |
String | Yes | |
comments |
String | No | |
foodRating |
integer | Yes | |
waitingTime |
integer | Yes | |
price |
float | Yes | |
photoOfOrder |
String | No | |
dateOfVisit |
String | Yes | Format: YYYY-MM-DD |
restaurantName |
String | Yes |
example:
{
"menuItem": "Carne Asada Tacos",
"restaurantType": "Mexican",
"comments": "The meat was a little dry and service was slow, but tasted good overall!",
"foodRating": 4,
"waitTime": 30,
"price": 6.4,
"photoOfOrder": "https://www.eatingonadime.com/wp-content/uploads/2018/05/easy-street-tacos.jpg",
"dateOfVisit": "2019-05-06",
"restaurantName": "Escorpion"
}
If you successfully createa board, the endpoint will return an HTTP response with a status code
201
and a body as below.
example
{
"id": 3,
"userId": 1,
"menuItem": "Carne Asada Tacos",
"restaurantType": "Mexican",
"comments": "The meat was a little dry and service was slow, but tasted good overall!",
"foodRating": 4,
"waitTime": 30,
"price": 6.4,
"photoOfOrder": "https://www.eatingonadime.com/wp-content/uploads/2018/05/easy-street-tacos.jpg",
"dateOfVisit": "2019-05-06",
"restaurantName": "Escorpion"
}
If your request has insufficient required fields, the endpoint will return code
400
and a body as follows:
{ "message": "Missing required parameter" }
If you are not logged in or your session has expired, the endpoint will return code
500
and a body as follows:
{ "message": "You are not authorized to perform that operation" }
Method Url: https://foodiefun-api.herokuapp.com/api/reviews/:reviewId
HTTP method: [DELETE]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
Authorization |
String | Yes | JWT authorization token |
name | type | required | description |
---|---|---|---|
reviewId |
Int | Yes | Id of specific review |
If the request if successful, the server will return an HTTP response with a status code
200
and body as follows:
{
"message": "Review deleted",
"review": {
"id": 1,
"userId": 1,
"menuItem": "Carne Asada Tacos",
"restaurantType": "Mexican",
"comments": "The meat was a little dry and service was slow, but tasted good overall!",
"foodRating": 4,
"waitTime": 30,
"price": 6.4,
"photoOfOrder": "https://www.eatingonadime.com/wp-content/uploads/2018/05/easy-street-tacos.jpg",
"dateOfVisit": "2019-05-06",
"restaurantName": "Escorpion"
}
}
If you are not logged in or the review doesn't belong to the user, the endpoint will return the status code
401
and a body as follows
{
"message": "Wrong credentials"
}
Method Url: https://foodiefun-api.herokuapp.com/api/reviews/:reviewId
HTTP method: [PUT]
name | type | required | description |
---|---|---|---|
Content-Type |
String | Yes | Must be application/json |
Authorization |
String | Yes | JWT authorization token |
name | type | required | description |
---|---|---|---|
reviewId |
Int | Yes | Id of specific review |
name | type | required | description |
---|---|---|---|
menuItem |
String | Yes | |
restaurantType |
String | Yes | |
comments |
String | No | |
foodRating |
integer | Yes | |
waitingTime |
integer | Yes | |
price |
float | Yes | |
photoOfOrder |
String | No | |
dateOfVisit |
String | Yes | Format: YYYY-MM-DD |
restaurantName |
String | Yes |
example:
{
"menuItem": "Updated Menu Item",
"restaurantType": "Mexican",
"comments": "The meat was a little dry and service was slow, but tasted good overall!",
"foodRating": 4,
"waitTime": 30,
"price": 6.4,
"photoOfOrder": "https://www.eatingonadime.com/wp-content/uploads/2018/05/easy-street-tacos.jpg",
"dateOfVisit": "2019-05-06",
"restaurantName": "Escorpion"
}
If the request if successful, the server will return an HTTP response with a status code
200
and body as follows:
{
"id": 1,
"userId": 1,
"menuItem": "Updated Menu Item",
"restaurantType": "Mexican",
"comments": "The meat was a little dry and service was slow, but tasted good overall!",
"foodRating": 4,
"waitTime": 30,
"price": 6.4,
"photoOfOrder": "https://www.eatingonadime.com/wp-content/uploads/2018/05/easy-street-tacos.jpg",
"dateOfVisit": "2019-05-06",
"restaurantName": "Escorpion"
}
If you are not logged in or the review doesn't belong to the user, the endpoint will return the status code
401
and a body as follows
{
"message": "Wrong credentials"
}