Giter Club home page Giter Club logo

byob's Introduction

BYOB [Build your own backend]

LIVE on heroku: Heroku Link

Summary

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.


Available Endpoints

Table of Contents


Getting a token

You may request a JSON web token by visiting the root URL of the application: /

You must have admin access to be able to POST/PATCH/DELETE to this API.


Muscle Groups (GET/GET:ID/POST/PATCH/DELETE)

GET /api/v1/muscle-groups

  • 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"
 }
]

GET by ID api/v1/muscle-groups/:id

  • 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"
 }
]

POST api/v1/muscle-groups

  • 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

PATCH api/v1/muscle-groups/:id

  • 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"

DELETE api/v1/muscle-groups

  • 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}"

Exercises (GET/GET?QUERY/GET:ID/POST/PATCH/DELETE)

GET api/v1/exercises

  • 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"
  },
]

GET api/v1/exercises?level=Beginner

  • 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"
  },

GET by ID api/v1/exercises/:id

  • 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"
 },
]

POST api/v1/exercises

  • 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

PATCH api/v1/exercises:id

  • 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"

DELETE api/v1/exercises

  • 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}"

Back To Top

byob's People

Contributors

kc2693 avatar amercado1014 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.