Rest API
Endpoint Documentation
- Resource description
Information
- Resource url
- Methods
- Parameters
- Request example
- Response examples
- Status and error codes
- Code sample
Keys to authorize the calls
Make requests via postman to test endpoints
NOTE : When you are adding anything to this document you can always use your favourite text editor but save the file with the same format as this document and also as a docx. . When all is ready to be uploaded you can use any doc.x to markdown convertors then copy the syntax in the markdown and paste it on to here Thank You
| Table | Method | Endpoint | Description |
|---|---|---|---|
| users | POST | /api/auth/register | Creates a new user profile using the information sent inside the body of the request and returns a message along with the new user and a JSON Web Token in the body of the response. |
| users | POST | /api/auth/login | Uses the credentials sent inside the body to authenticate the user. On successful login, returns a message with the user profile and a JSON Web Token token in the body of the response. |
REGISTER
Registers a user
Method Url: /api/auth/register
HTTP method:[POST]
Headers
| name | type | required | description |
|---|---|---|---|
| Content-Type | String | Yes | Must be application/json |
Body
| name | type | required | description |
|---|---|---|---|
| username | string | Yes | Username unique |
| String | Yes | Must be unique | |
| password | String | Yes | Must be unique |
| password | string | yes | Must be the same with Password |
example:
{
"Username":"bigmuscle467"
"email": "email@gmail.com"
"password": "password123",
}
Response
201 (Created)
( If you successfully register a user the endpoint will return an HTTP response with a status code 201 and a body as below.)
example:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI3IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTQ0MzM1NjUxLCJleHAiOjE1NzU4OTMyNTF9.uqd2OHBYkGQpwjLTPPiPWYkYOKlG7whQDFkk46xFXoX"
}
400 (Bad Request)
( If you are missing an email or password for registration, the endpoint will return an HTTP response with a status code 400 and a body as below. )
example:
{
"message": "Oops, looks like this email already exists"
}
500 (Internal Server Error)
( 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": "Oops, something went wrong while registering"
}
LOGIN
Logs a user in
Method Url: /api/auth/login
HTTP method:[POST]
Headers
| name | type | required | description |
|---|---|---|---|
| Content-Type | String | Yes | Must be application/json |
Body
| name | type | required | description |
|---|---|---|---|
| String | Yes | Must match an email in the database | |
| password | String | Yes | Must match a password in the database corresponding to email above |
example:
{
"email": "email@gmail.com"
"password": "password123",
}
Response
200 (OK)
( If you successfully login, the endpoint will return an HTTP response with a status code 200 and a body as below.)
example:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MDwiaWF0IjoxNTQ0MzM1NjUxLCJleHAuOjE1NzU4OTMyNTF9.uqd2OHBYkGQpwjLTPPiPWYkYOKlG7whQDFkk46xGXnE",
}
401 (Unauthorized)
( If you fail to login, the endpoint will return an HTTP response with a status code 401 which indicates the email and or password entered is not valid. )
example:
{
message: "Oops, username or password is incorrect"
}
500 (Bad Request)
( 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": "Oops, something went wrong while logging in"
}
GET USER
Get user profile by user id
Method Url: /api/user/:id
HTTP method:[GET]
Headers
| 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 applicant |
Response
200 (OK)
( 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":"25",
"username":"BigMuscle456",
"Password":" TokenEncrypted:"J67cvcjcbchcj74kF-hash12-hyJR578iKxI",
"email":"bigmuscles@befit.com",
"gender":"M",
"weight":"100lbs",
"Height":"30cm",
"User_level": "Intermediate",
"Created_at": "2019/08/18",
"Updated_at": "2019/08/19"
}
404 (Not Found)
( If the provided userId doesn't have a profile, the endpoint will return an HTTP response with a status code 404 and a body as below. )
example:
{
"message": "Sorry, but that profile doesn't exist"
}
500 (Internal Server Error)
( 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 profile"
}
ADD USER / CREATE
Method Url: /api/user
HTTP method:[POST]
Headers
| name | type | required | description |
|---|---|---|---|
| Content-Type | String | Yes | Must be application/json |
| Authorization | String | Yes | JSON Web Token |
Body
| name | type | required | description |
|---|---|---|---|
| username | String | Yes | Cannot be an empty field |
| password | String | Yes | Cannot be an empty field |
| String | Yes | Cannot be an empty field | |
| gender | String | Yes | Cannot be an empty field |
| weight | Integer | Yes | Cannot be an empty field |
| height | Integer | Yes | Cannot be an empty field |
| user_level | integer | Yes | Cannot be an empty field |
| created_at | timestamp | ||
| updated_at | timestamp |
example:
{
"Id":"25",
"username":"BigMuscle456",
"Password":" TokenEncrypted:"J67cvcjcbchcj74kF-hash12-hyJR578iKxI",
"email":"bigmuscles@befit.com",
"gender":"M",
"weight":"100lbs",
"Height":"30cm",
"User_level": "Intermediate",
"Created_at": "2019/08/18",
"Updated_at": "2019/08/19"
}
Response
201 (Created)
( If you successfully create a user profile, the endpoint will return an HTTP response with a status code 201 and a body as below. )
example:
{
"Id":"25",
"username":"BigMuscle456",
"Password":" TokenEncrypted:"J67cvcjcbchcj74kF-hash12-hyJR578iKxI",
"email":"bigmuscles@befit.com",
"gender":"M",
"weight":"100lbs",
"Height":"30cm",
"User_level": "Intermediate",
"Created_at": "2019/08/18",
"Updated_at": "2019/08/19"
}
500 (Internal Server Error)
( 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": "Oops, something went wrong while creating your profile"
}
UPDATE USER
Update user by user id
Method Url: /api/user/:id
HTTP method:[PUT]
Headers
| name | type | required | description |
|---|---|---|---|
| Content-Type | String | Yes | Must be application/json |
| Authorization | String | Yes | JSON Web Token |
Parameters
| name | type | required | description |
|---|---|---|---|
| id | Integer | Yes | ID of a specific applicant |
Body
| name | type | required | description |
|---|---|---|---|
| Id | Integer | Yes | Cannot be an empty field |
| username | String | Yes | Cannot be an empty field |
| password | String | Yes | Cannot be an empty field |
| String | Yes | Cannot be an empty field | |
| gender | String | Yes | Cannot be an empty field |
| weight | Integer | Yes | Cannot be an empty field |
| height | Integer | Yes | Cannot be an empty field |
| user_level | integer | Yes | Cannot be an empty field |
| created_at | timestamp | ||
| updated_at | timestamp |
example:
{
"Id":"25",
"username":"BigMuscle456",
"Password":" TokenEncrypted:"J67cvcjcbchcj74kF-hash12-hyJR578iKxI",
"email":"bigmuscles@befit.com",
"gender":"M",
"weight":"100lbs",
"Height":"30cm",
"User_level": "Intermediate",
"Created_at": "2019/08/18",
"Updated_at": "2019/08/19"
}
Response
200 (OK)
( If user 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:
{
"Id":"25",
"username":"BigMuscle456",
"Password":" TokenEncrypted:"J67cvcjcbchcj74kF-hash12-hyJR578iKxI",
"email":"bigmuscles@befit.com",
"gender":"M",
"weight":"105lbs",
"Height":"30cm",
"User_level": "Advanced",
"Created_at": "2019/08/18",
"Updated_at": "2019/08/15"
}
404 (Not Found)
( If the applicant profile for the specified id can't be found in the database, the endpoint will return an HTTP response with a status code 404 and a body as below. )
example:
{
"message": "Oops, doesn't look like that profile exists"
}
500 (Internal Server Error)
( 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": "Oops, something went wrong while updating this profile"
}
DELETE USER / ACCOUNT
Delete user by user id
Method Url: /api/user/:id
HTTP method:[DELETE]
Headers
| name | type | required | description |
|---|---|---|---|
| Content-Type | String | Yes | Must be application/json |
| Authorization | String | Yes | JSON Web Token |
Parameters
| name | type | required | description |
|---|---|---|---|
| id | Integer | Yes | ID of a specific applicant |
Response
200 (OK)
( If 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": "User successfully deleted"
}
404 (Not Found)
( If the applicant profile for the specified id can't be found in the database, the endpoint will return an HTTP response with a status code 404 and a body as below.)
example:
{
"message": "Oops, doesn't look like that profile exists"
}
500 (Bad Request)
( 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": "Oops, something went wrong while deleting this profile }
GET WORKOUTS
Get workout by user id
Method Url: /api/user/workouts/:id
HTTP method:[GET]
Headers
| name | type | required | description |
|---|---|---|---|
| Content-Type | String | Yes | Must be application/json |
| Authorization | String | Yes | JSON Web Token |
Response
200 (OK)
( If workout 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"
"workout_name":"Abs",
"workout_description": "These proven exercises, demonstrated by a certified personal trainer, target all major abdominal muscles. Spending just minutes a day can strengthen your core and tone your abs. The routine's simple interface, complete with video and timer, allows you to easily follow along and understand each exercise",
"Image_url": "https//something.abs/muscle.png" ,
"created_at": "2019/08/22" ,
"updated_at": "2019/08/24",
},
]
404 (Not Found)
( A 404 (Not Found) response has two possible outcomes one if the user doesn't have any workouts or if the provided user doesn't have a profile, the endpoint will return an HTTP response with a status code 404 and a body as below. )
example:
{
"message": "Oops, this user doesn't have workout yet"
}
or
{
"message": "Oops, doesn't look like that workout exists"
}
500 (Internal Server Error)
( 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": "Oops, something went wrong while fetching this workout"
}
ADD WORKOUTS
Add workout
Method Url: /api/user/workout
HTTP method:[POST]
Headers
| name | type | required | description |
|---|---|---|---|
| Content-Type | String | Yes | Must be application/json |
| Authorization | String | Yes | JSON Web Token |
Body
| name | type | required | description |
|---|---|---|---|
| workoukID | Integer | Yes | Must match a user's id in the database |
| workout_name | String | Yes | Cannot be an empty field |
| workout_description | String | Yes | Cannot be an empty field |
| image_url | String | Yes | Cannot be an empty field |
| created _at | timestamps | Yes | Cannot be an empty field |
| updated_at | timestamps | Yes | Cannot be an empty field |
example:
{
"userId": 1,
"UserWorkout": [
{
"workout_name":"Abs",
"workout_description": "These proven exercises, demonstrated by a certified personal trainer, target all major abdominal muscles. Spending just minutes a day can strengthen your core and tone your abs. The routine's simple interface, complete with video and timer, allows you to easily follow along and understand each exercise",
"Image_url": "https//something.abs/muscle.png" ,
"created_at": "2019/08/22" ,
"updated_at": "2019/08/24" },
]
}
Response
201 (Created)
( If you successfully create applicant workout, the endpoint will return an HTTP response with a status code 201 and a body as below. )
example:
[
{
"Id": "1"
"workout_name":"Abs",
"workout_description": "These proven exercises, demonstrated by a certified personal trainer, target all major abdominal muscles. Spending just minutes a day can strengthen your core and tone your abs. The routine's simple interface, complete with video and timer, allows you to easily follow along and understand each exercise",
"Image_url": "https//something.abs/muscle.png" ,
"created_at": "2019/08/22" ,
"updated_at": "2019/08/24",
},
]
404 (Not Found)
( If we can't manage to add the work out to the database or to our list, the endpoint will return an HTTP response with a status code 404 and a body as below. )
example:
{
"message": "Oops, could not add workout"
}
400 (Bad Request)
( If you are missing any of the required field(s), the endpoint will return an HTTP response with a status code 400 and a body as below relating to the missing field(s). )
example:
{
"message": "Please provide a workout_name"
}
500 (Internal Server Error)
( 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 trying to add abs"
}
UPDATE WORKOUT
Update individual workout using workout by id
Method Url: /api/user/workout/:id
HTTP method:[PUT]
Headers
| name | type | required | description |
|---|---|---|---|
| Content-Type | String | Yes | Must be application/json |
| Authorization | String | Yes | JSON Web Token |
Parameters
| name | type | required | description |
|---|---|---|---|
| id | Integer | Yes | ID of a specific education object |
Body
| name | type | required | description |
|---|---|---|---|
| workoukID | Integer | Yes | Must match a user's id in the database |
| workout_name | String | Yes | Cannot be an empty field |
| workout_description | String | Yes | Cannot be an empty field |
| image_url | String | Yes | Cannot be an empty field |
| created _at | timestamps | Yes | Cannot be an empty field |
| updated_at | timestamps | Yes | Cannot be an empty field |
example:
[
{
"Id": "1"
"workout_name":"Arms",
"workout_description": "Lorem ipsum arms instead of Abs a certified personal trainer, target all major abdominal muscles. Spending just minutes a day can strengthen your core and tone your abs. The routine's simple interface, complete with video and timer, allows you to easily follow along and understand each exercise",
"Image_url": "https//something.abs/muscle.png" ,
"created_at": "2019/08/22" ,
"updated_at": "2019/08/24",
},
]
Response
200 (OK)
( If the workout object 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:
{
[
{
"Id": "23"
"workout_name":"Arms",
"workout_description": "Lorem ipsum arms instead of Abs a certified personal trainer, target all major abdominal muscles. Spending just minutes a day can strengthen your core and tone your abs. The routine's simple interface, complete with video and timer, allows you to easily follow along and understand each exercise",
"Image_url": "https//something.abs/muscle.png" ,
"created_at": "2019/08/22" ,
"updated_at": "2019/08/24",
},
]
}
404 (Not Found)
( If the workout object for the specified id can't be found in the database, the endpoint will return an HTTP response with a status code 404 and a body as below.)
example:
{
"message": "Oops, doesn't look like that workout doesnt exists"
}
400 (Bad Request)
( If you are missing any of the required field(s), the endpoint will return an HTTP response with a status code 400 and a body as below relating to the missing field(s).)
example:
{
"message": "Please provide a workou_name"
}
500 (Internal Server Error)
( 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": "Oops, something went wrong while updating this workout"
}
DELETE WORKOUT
Delete workout by id
Method Url: /api/user/workout/:id
HTTP method:[DELETE]
Headers
| name | type | required | description |
|---|---|---|---|
| Content-Type | String | Yes | Must be application/json |
| Authorization | String | Yes | JSON Web Token |
Parameters
| name | type | required | description |
|---|---|---|---|
| id | Integer | Yes | ID of workout |
Response
200 (OK)
( If the workout object 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": "Workout successfully deleted"
}
404 (Not Found)
( If the Workout object specified ID in the URL parameters is deleted successfully in the database, the endpoint will return an HTTP response with a status code 404 and a body as below.)
example:
{
"message": "Oops, doesn't look like this workout exists"
}
500 (Bad Request)
( 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": "Oops, something went wrong while deleting this workout"
}