URI /api/auth
| Method | URI | Description |
|---|---|---|
POST |
/login |
Authenticate User |
POST |
/register |
Register User |
-
Data Constraints
{ email: "[valid email address]" password: "[password in plain text]" }
-
Data Example
{ email: "john.smith@gmail.com password: "password" } -
Success Response:
- Code: 200 - OK
- Example
{ message: "User Authenticated", token: "[json web token]", user: { "id": 1, "name": "John Smith", "email": "john.smith@gmail.com" } }
- Example
- Code: 200 - OK
-
Error Response:
- Code: 401 - UNAUTHORIZED
- Examples
{ message: "Invalid password provided" }{ message: "No account associated with john.smith@gmail.com" }
- Examples
- Code: 400 - BAD REQUEST
- Example
{ "message": "Missing credentials" }
- Example
- Code: 500 - INTERNAL SERVER ERROR
- Example
{ "message": "Internal Server Error" }
- Example
- Code: 401 - UNAUTHORIZED
- Data Constraints
{ name: "[user's name]" email: "[valid email address]" password: "[password in plain text]" }
-
Data Example
{ name: "John Smith" email: "john.smith@gmail.com password: "password" } -
Success Response:
- Code: 201 - CREATED
- Example
{ "message": "john.smith@gmail.com has been registered.", "token": "[json web token]", "newUser": { "id": 1, "name": "John Smith", "email": "john.smith@gmail.com" } }
- Example
- Code: 201 - CREATED
-
Error Response:
- Code: 409 - CONFLICT
Example{ message: "Account with email john.smith@gmail.com is already exists" } - Code: 400 BAD REQUEST
Example{ "message": "Missing credentials" } - Code: 500 INTERNAL SERVER ERROR
Example{ "message": "Internal Server Error" }
- Code: 409 - CONFLICT
/api/user/<user.id>/<entry.date>/
Must be logged in
Returns entry array
Ex:
{
"entry": [
{
"name": "Test",
"id": 1,
"user_id": 1,
"date": "2020-07-24T05:00:00.000Z",
"meal_type": "breakfast",
"edamam_food_id": "3",
"measurement_uri": "measurement_uri",
"measurement_name": "measurement_name",
"food_name": "food_name",
"quantity": 2,
"calories_kcal": 2,
"fat_g": "0.50",
"carbs_g": "0.50",
"protein_g": "0.50"
},
{
"name": "Test2",
"id": 2,
"user_id": 1,
"date": "2020-07-24T05:00:00.000Z",
"meal_type": "dinner",
"edamam_food_id": "3",
"measurement_uri": "measurement_uri",
"measurement_name": "measurement_name",
"food_name": "food_name",
"quantity": 2,
"calories_kcal": 2,
"fat_g": "0.50",
"carbs_g": "0.50",
"protein_g": "0.50"
}
]
}/api/user/<user.id>/
Must be logged in
Must provide:
- valid user_id
- date
- edamam_food_id
- measurement_uri
- measurement_name
- food_name
- quantity
- calories_kcal
- fat_g
- carbs_g
- protein_g
- meal_type -
Options:
- breakfast
- lunch
- snack
- dinner
- water
Returns a new entry
Ex:
[
{
"id": 3,
"user_id": 1,
"date": "2020-07-24T05:00:00.000Z",
"meal_type": "snack",
"edamam_food_id": "3",
"measurement_uri": "measurement_uri",
"measurement_name": "measurement_name",
"food_name": "food_name",
"quantity": 2,
"calories_kcal": 2,
"fat_g": "0.50",
"carbs_g": "0.50",
"protein_g": "0.50"
}
]/api/user/<user.id>/<log_entry.id>
Must be logged in
Required:
- valid user id
- valid log_entry id
Returns the following:
{
"updated": 1
}/api/user/<user.id>/<log_entry.id>
Must be logged in
Required:
- valid user id
- valid log_entry id
Returns the following:
{
"removed": 1
}