This is an Express application providing a REST API to the Healthy Food application.
Generally it is a RESTful API and returns results in JSON format.
It allows to register a new user.
POST /api/auth/register
-
Body
{ "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "password": "[user password in plain text]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }
Required fields:
name, surname, username, password, email
-
Success Response:
Status Code: 200 OK
Body:
{ "user": { "_id" : "[user identifier]", "isAdmin": [true | false], "name": "[user first name]" }, "token": "[JWT Token]" }
-
Error Response:
-
Status Code: 400 Bad Request
Body:
{ "message": "User already registered" }
-
It allows user to log in.
POST /api/auth/login
-
Body
{ "email": "[valid user email address]", "password": "[user password in plain text]" }
Required fields:
email, password
-
Success Response:
Status Code: 200 OK
Body:
{ "user": { "_id" : "[user identifier]", "isAdmin": [true | false], "name": "[user first name]" }, "token": "[JWT Token]" }
The JWT token is also returned in response headers as
X-Auth-Token
. This token must be sent in every future requests where user need to be authenticated. -
Error Response:
-
Status Code: 401 Unauthorized
Body:
{ "message": "Invalid email or password." }
-
Status Code: 400 Bad Request
Body:
{ "message": "Invalid email or password." }
-
It sends user an email with the link to reset his/her password.
POST /api/user
-
Body
{ "email": "[valid user email address]" }
Required fields:
email
-
Success Response:
Status Code: 200 OK
Body:
{ "message": "E-mail has been sent" }
-
Error Response:
-
Status Code: 404 Not found
Body:
{ "message": "User not found." }
-
It allows user to reset his/her password.
POST /api/user/:id/:token
-
Params
{ "id": "[user identifier]", "password": "[user new password in plain text]" }
Required fields:
id, password
-
Success Response:
Status Code: 200 OK
-
Error Response:
-
Status Code: 401 Unauthorized
Body:
{ "message": "Access denied" }
-
Status Code: 404 Not found
Body:
{ "message": "User not found." }
-
It returns data about logged in user.
GET /api/user/:id/:token
-
Params
{ "id": "[user identifier]", "token": "[JWT Token]" }
Required fields:
id, token
-
Success Response:
Status Code: 200 OK
Body:
{ "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "password": "[user password in plain text]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }
-
Error Response:
-
Status Code: 400 Unauthorized
Body:
{ "message": "Invalid token." }
-
Status Code: 401 Unauthorized
Body:
{ "message": "Access denied. No token provided." }
-
It returns logged in user all recipes.
GET /api/user/recipes
-
Body
{ "userId": "[user identifier]" }
Required fields:
userId
-
Success Response:
Status Code: 200 OK
Body:
[ { "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] } ]
-
Error Response:
-
Status Code: 400 Unauthorized
Body:
{ "message": "Invalid token." }
-
Status Code: 404 Not found
Body:
{ "message": "No recipes found" }
-
It returns logged in user single recipe.
GET /api/user/recipes/:id
-
Params
{ "id": "[recipe identifier]" }
-
Success Response:
Status Code: 200 OK
Body:
{ "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] }
-
Error Response:
-
Status Code: 400 Unauthorized
Body:
{ "message": "Invalid token." }
-
Status Code: 404 Not found
-
It allows to create a new recipe. `
POST /api/user/recipes
-
Body
{ "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] }
Required fields:
author, title, mealType, ingredients
-
Success Response:
Status Code: 201 OK
Body:
{ "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] }
-
Error Response:
-
Status Code: 400 Unauthorized
Body:
{ "message": "Invalid token." }
-
It allows to update user recipe. `
PATCH /api/user/recipes/:id
-
Params
"recipe_id": "[recipe identifier]"
-
Body
{ "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] }
-
Success Response:
Status Code: 200 OK
Body:
{ "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] }
-
Error Response:
-
Status Code: 400 Unauthorized
Body:
{ "message": "Invalid token." }
-
It allows to delete user recipe. `
DELETE /api/user/recipes/:id
-
Params
"recipe_id": "[recipe identifier]"
-
Success Response:
Status Code: 200 OK
-
Error Response:
-
Status Code: 400 Unauthorized
Body:
{ "message": "Invalid token." }
-
Status Code: 404 Not Found
Body:
{ "message": "Recipe not found. Perhaps it was already deleted" }
-
It returns logged in user all meal plans.
GET /api/user/mealplans
-
Body
{ "userId": "[user identifier]" }
Required fields:
userId
-
Success Response:
Status Code: 200 OK
Body:
[ { "days": [ { "mealType": ["breakfast" | "lunch" | "dinner"], "recipe": { "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] }, "dayNumber": "[number of days]" } ], "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[meal plan title]", "tags": ["meal plan tags"], "img": "[img base 64 format]", "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] } ]
-
Error Response:
-
Status Code: 400 Unauthorized
Body:
{ "message": "Invalid token." }
-
Status Code: 404 Not found
Body:
{ "message": "Meal plans don't exist" }
-
It returns logged in user single meal plan.
GET /api/user/mealplans/:id
-
Params
{ "id": "[recipe identifier]" }
-
Success Response:
Status Code: 200 OK
Body:
{ "days": [ { "mealType": ["breakfast" | "lunch" | "dinner"], "recipe": { "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] }, "dayNumber": "[number of days]" } ], "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[meal plan title]", "tags": ["meal plan tags"], "img": "[img base 64 format]", "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] }
-
Error Response:
-
Status Code: 400 Unauthorized
Body:
{ "message": "Invalid token." }
-
Status Code: 404 Not found
Body:
{ "message": "Meal plan doesn't exist" }
-
It allows to create a new meal plan. `
POST /api/user/mealplans
-
Body
{ "days": [ { "mealType": ["breakfast" | "lunch" | "dinner"], "recipe": { "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] }, "dayNumber": "[number of days]" } ], "title": "[meal plan title]", "tags": ["meal plan tags"], "img": "[img base 64 format]", }
Required fields:
days, title
-
Success Response:
Status Code: 201 OK
Body:
{ "days": [ { "mealType": ["breakfast" | "lunch" | "dinner"], "recipe": { "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] }, "dayNumber": "[number of days]" } ], "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[meal plan title]", "tags": ["meal plan tags"], "img": "[img base 64 format]" }
-
Error Response:
-
Status Code: 400 Unauthorized
Body:
{ "message": "Invalid token." }
-
It allows to update user meal plan. `
PATCH /api/user/mealplans/:id
-
Params
"_id": "[meal plan identifier]"
-
Body
{ "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] }
-
Success Response:
Status Code: 200 OK
Body:
{ "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] }
-
Error Response:
-
Status Code: 400 Unauthorized
Body:
{ "message": "Invalid token." }
-
Status Code: 404 Not found
Body:
{ "message": "Meal plan doesn't exist" }
-
It allows to delete user meal plan. `
DELETE /api/user/mealplans/:id
-
Params
"_id": "[meal plan identifier]"
-
Success Response:
Status Code: 200 OK
-
Error Response:
-
Status Code: 400 Unauthorized
Body:
{ "message": "Invalid token." }
-
Status Code: 404 Not Found
Body:
{ "message": "Meal plan doesn't exist" }
-
It returns logged in user favourite meal plans.
GET /api/user/favourite/mealplans
-
Body
{ "userId": "[user identifier]" }
Required fields:
userId
-
Success Response:
Status Code: 200 OK
Body:
[ { "days": [ { "mealType": ["breakfast" | "lunch" | "dinner"], "recipe": { "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] }, "dayNumber": "[number of days]" } ], "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[meal plan title]", "tags": ["meal plan tags"], "img": "[img base 64 format]", "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] } ]
-
Error Response:
-
Status Code: 400 Unauthorized
Body:
{ "message": "Invalid token." }
-
Status Code: 404 Not found
Body:
{ "message": "Meal plans not found" }
-
It returns logged in user favourite recipes.
GET /api/user/favourite/recipes
-
Body
{ "userId": "[user identifier]" }
Required fields:
userId
-
Success Response:
Status Code: 200 OK
Body:
[ { "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] } ]
-
Error Response:
-
Status Code: 400 Unauthorized
Body:
{ "message": "Invalid token." }
-
Status Code: 404 Not found
Body:
{ "message": "Recipe not found" }
-
It allows logged in user to update a status of favourite meal plans.
PATCH /api/user/favourite/mealplans/:id
-
Body
{ "userId": "[user identifier]" }
Required fields:
userId
-
Params
{ "id": "[meal plan identifier]" }
-
Success Response:
Status Code: 200 OK
Body:
{ "message": "Updated mealplan favourite status" }
-
Error Response:
-
Status Code: 400 Unauthorized
Body:
{ "message": "Invalid token." }
-
It allows logged in user to update a status of favourite recipes.
PATCH /api/user/favourite/recipes/:id
-
Body
{ "userId": "[user identifier]" }
Required fields:
userId
-
Params
{ "id": "[recipe identifier]" }
-
Success Response:
Status Code: 200 OK
Body:
{ "message": "Updated recipe favourite status" }
-
Error Response:
-
Status Code: 400 Unauthorized
Body:
{ "message": "Invalid token." }
-
It returns all meal plans and recipes.
GET /api/pageResource
-
Body
No body data required.
-
Success Response:
Status Code: 200 OK
Body:
{ "mealPlans":[ { "days": [ { "mealType": ["breakfast" | "lunch" | "dinner"], "recipe": { "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] }, "dayNumber": "[number of days]" } ], "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[meal plan title]", "tags": ["meal plan tags"], "img": "[img base 64 format]", "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] } ], "recipes":[ { "author": { "name": "[user first name]", "surname": "[user last name]", "username": "[username]", "email": "[valid user email address]", "phoneNumber": "[user phone number]", "isAdmin": [true | false] }, "title": "[recipe title]", "tags": ["recipe tags"], "time": [number of minutes], "mealType": ["breakfast" | "lunch" | "dinner"], "ingredients": [ { "name": "[name of ingredient]", "quantity": { "number": [quantity of ingredient], "unit": ["kg" | "kg" | "g" | "ml" | "pcs" | "tablespoon" | "teaspoon" | "cup" | "pinch" | "slice"] } } ], "description": "[description of recipe]", "recipe" : "[stpes of preparing recipe]", "img": "[img base 64 format]", "peopleNumber": [number of people], "likes": [ { "name": "[user first name]", "surname": "[user last name]" } ] }] }