Giter Club home page Giter Club logo

qs-js-api's Introduction

You'll need to do a little prep work to set this api up on your own computer.

to set up your environment:

  • npm install nodemon --save-dev
  • npm install knex pg --save
  • npm install knex -g
  • setup your local postges database with: CREATE DATABASE quantified_self; CREATE DATABASE quantified_self_test;
  • knex init
  • knex migrate:latest
  • knex seed:run

to run and see the beautifulness of the API:

The following endpoints are available. All endpoints will return the data as JSON.

Food Endpoints:

  • GET /api/v1/foods - returns all foods currently in the database
  • GET /api/v1/foods/:id - returns the food object with the specific :id you've passed in or 404 if the food is not found
  • POST /api/v1/foods - allows creating a new food with the parameters: { food: { name: "Name of food here", calories: "Calories here"} } If food is successfully created, the food item will be returned. If the food is not successfully created, a 400 status code will be returned. Both name and calories are required fields.
  • PATCH /api/v1/foods/:id - allows one to update an existing food with the parameters: { food: { name: "Name of food here", calories: "Calories here"} } If food is successfully updated (name and calories are required fields), the food item will be returned. If the food is not successfully updated, a 400 status code will be returned.
  • DELETE /api/v1/foods/:id - will delete the food with the id passed in. If the food can't be found, a 404 will be returned.

Meal Endpoints:

  • GET /api/v1/meals - returns all the meals in the database along with their associated foods
  • GET /api/v1/meals/:meal_id/foods - returns all the foods associated with the meal with an id specified by :meal_id or a 404 if the meal is not found
  • POST /api/v1/meals/:meal_id/foods/:id - adds the food with :id to the meal with :meal_id This creates a new record in the MealFoods table to establish the relationship between this food and meal. If the meal/food cannot be found, a 404 will be returned.
  • DELETE /api/v1/meals/:meal_id/foods/:id - removes the food with :id from the meal with :meal_id This deletes the existing record in the MealFoods table that creates the relationship between this food and meal. If the meal/food cannot be found, a 404 will be returned.

qs-js-api's People

Contributors

nmcolome avatar squeemishly avatar

Watchers

James Cloos avatar  avatar

Forkers

squeemishly

qs-js-api's Issues

refactor meals tests

use methods created in meals model to simplify tests
move meals tests to their own file

refactor meals

move logic out of server.js to models and controllers

refactor foods

move logic out of server.js to models and controllers

Meal Endpoint: DELETE /api/v1/meals/:meal_id/foods/:id

DELETE /api/v1/meals/:meal_id/foods/:id - removes the food with :id from the meal with :meal_id
This deletes the existing record in the MealFoods table that creates the relationship between this food and meal. If the meal/food cannot be found, a 404 will be returned.

Meal Endpoint: POST /api/v1/meals/:meal_id/foods/:id

POST /api/v1/meals/:meal_id/foods/:id - adds the food with :id to the meal with :meal_id
This creates a new record in the MealFoods table to establish the relationship between this food and meal. If the meal/food cannot be found, a 404 will be returned.

refactor foods-test

use methods created in foods model to simplify tests
move foods tests to their own file

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.