LIVE on heroku: Heroku Link
This was a 5-day school project using Node, Knex, and Express to build our own API & to reinforce our understanding of CRUD methods, querying a database, responding with JSON data, and learning how to authenticate with JWTs. We decided to use fitness data. Our database has two tables, with a one-to-many relationship. One table for muscle groups, and one for individual exercises that relate to each group.
This project uses TravisCI, and is fully tested with Mocha and Chai.
- Getting a Token
- Muscle Groups
- Exercises
- Retrieves all muscle groups in the database.
- Response will contain an array of objects containing each exercise.
Example response:
[
{
"id": 1,
"muscle_group": "Abdominals",
"targeted_area": "Lower",
"train_with": "Biceps, Triceps",
"created_at": "2018-05-15T22:34:20.881Z",
"updated_at": "2018-05-15T22:34:20.881Z"
},
{
"id": 2,
"muscle_group": "Abdominals",
"targeted_area": "Obliques",
"train_with": "Biceps, Triceps",
"created_at": "2018-05-15T22:34:20.881Z",
"updated_at": "2018-05-15T22:34:20.881Z"
},
{
"id": 3,
"muscle_group": "Abdominals",
"targeted_area": "Total",
"train_with": "Biceps, Triceps",
"created_at": "2018-05-15T22:34:20.881Z",
"updated_at": "2018-05-15T22:34:20.881Z"
}
]
- Retrieve a specific muscle-group by ID.
- Response will contain an array with an object containing the specified muscle group.
Example response:
[
{
"id": 3,
"muscle_group": "Abdominals",
"targeted_area": "Total",
"train_with": "Biceps, Triceps",
"created_at": "2018-05-15T22:34:20.881Z",
"updated_at": "2018-05-15T22:34:20.881Z"
}
]
- REQUIRED parameters in the body of your request:
- muscle_group: The name of the muscle group. This does not have to be unique.
- targeted_area: The specific area. This is a unique key. For muscle-groups that will only have one targeted area, it is recommended to put 'Total'.
- train_with: Other muscle groups that are recommended to be trained with this muscle group.
- Response will contain the ID of the newly created group. You can view this exercise with a get request to the specific id: GET api/v1/muscle-groups/:id
Example request body:
{
"muscle_group": "Abdominals",
"targeted_area": "Lower",
"train_with": "Biceps, Triceps"
}
Example response:
Status: 201
id: 34
- REQUIRED to put id of muscle-group-to-patch in request URL
- Response will contain a message telling you that the muscle group was updated.
Example response:
Status: 200
"Updated muscle group"
- You must specify a muscle group ID in the body of your request
- You must delete all exercises associated with the muscle group first or you will receive an error.
- Response will contain a message telling you that the muscle group was deleted.
Example response:
Status: 200
"Deleted exercise with id {ID HERE}"
- Retrieves all muscle groups in the database.
- Response will contain an array of objects containing each exercise.
Example response:
[
{
"exercise": "Full Reverse Crunch",
"level": "Advanced",
"method": "FW",
"upper_lower_core": "Core",
"joint": "M",
"targeted_area": "Lower"
},
{
"exercise": "Bent-Knee Medicine Ball Hip Rotation",
"level": "Advanced",
"method": "FW",
"upper_lower_core": "Core",
"joint": "M",
"targeted_area": "Obliques"
},
{
"exercise": "Machine Curl",
"level": "Beginner",
"method": "M",
"upper_lower_core": "Upper",
"joint": "S",
"targeted_area": "Biceps"
},
]
-
Retrieves all exercises of a specified level (Beginner, Intermediate, or Advanced)
-
Response will contain an array of objects containing each exercise.
Example response:
[
{
"exercise": "Full Reverse Crunch",
"level": "Advanced",
"method": "FW",
"upper_lower_core": "Core",
"joint": "M",
"targeted_area": "Lower"
},
{
"exercise": "Bent-Knee Medicine Ball Hip Rotation",
"level": "Advanced",
"method": "FW",
"upper_lower_core": "Core",
"joint": "M",
"targeted_area": "Obliques"
},
- Retrieve a specific exercise by ID.
- Response will contain an array with an object containing the specified exercise.
Example response:
[
{
"exercise": "Machine Curl",
"level": "Beginner",
"method": "M",
"upper_lower_core": "Upper",
"joint": "S",
"targeted_area": "Biceps"
},
]
- REQUIRED parameters in the body of your request:
- exercise: Name of the exercise
- level: Beginner/Intermediate/Advanced
- method: FW/C/M (Free Weights, Cables, or Machine). The method this exercise uses.
- upper_lower_core: Upper/Lower/Core. Which part of the muscle group does this exercise target?
- joint: M/S. M for Multi-Joint Exercise, S for Single-Joint Exercise
- muscle_group_id: The ID of the muscle group this exercise will belong to. If none exists, you must POST to muscle-groups beforehand.
- Response will contain the id of the newly-created exercise. You can view this exercise with a get request to the specific id: GET
api/v1/exercises/:id
Example request body:
{
"exercise": "Spell Caster",
"level": "Advanced",
"method": "FW",
"upper_lower_core": "Core",
"joint": "M",
"muscle_group_id": 1
}
Example response:
Status: 201,
id: 285
- REQUIRED to put id of exercise-to-patch in request URL
- Response will contain a message telling you that the exercise was updated.
Example response:
Status: 200
"Updated exercise"
- YOU MUST specify an exercise ID in the body of your request
- Response will contain a message telling you that the exercise was deleted.
Example response:
Status: 200
"Deleted exercise with id {ID HERE}"