Calorie Counts is a 2 week paired project for Module 4 at Turing School of Software and Design, made by Rob Stringer and Logan Pile. The project implements the Express framework with Node.js to build a RESTful API returning meal and food information. A Postgres database with many to many schema holds meal and food information to track calorie consumption. Also implemented is a single page front end with JQuery and ajax calls to the API.
Git Setup
$ git clone https://github.com/lpile/calorie-counts
$ cd calorie_counts
$ npm install
Database & Models
$ npx sequelize db:create
$ npx sequelize db:migrate
$ npx sequelize db:seed:all
Testing
$ npm install babel-jest supertest shelljs -D
$ npm install jest-cli
$ npm test
node 10.16.0
npm 6.9.0
Jest was used to test all endpoints. Edge cases were also covered, as well as many status codes for different scenarios. TravisCI was also used for integrating tests and deployment.
- Node.js
- Express
- TravisCI
- Jest
- JQuery
- HTML5/CSS3/SCSS
Request:
GET /api/v1/foods
Content-Type: application/json
Accept: application/json
Response:
status: 200
body:
{
foods: [
{
"id": 1,
"name": "Banana",
"calories": 150
},
{
"id": 2,
"name": "Apple",
"calories": 10
}
]
}
Request:
GET /api/v1/foods/:id
Content-Type: application/json
Accept: application/json
Response:
status: 200
body:
{
"id": 1,
"name": "Banana",
"calories": 150
}
Request:
POST /api/v1/foods
Content-Type: application/json
Accept: application/json
body:
{
"food":
{
"name": "Name of food here",
"calories": "Calories here"
}
}
Response:
status: 201
body:
{
"message": "FOODNAME has been added"
}
Request:
PATCH /api/v1/foods/:id
Content-Type: application/json
Accept: application/json
body:
{
"food":
{
"name": "Mint",
"calories": "14"
}
}
Response:
status: 202
body:
{
"id": 1,
"name": "Mint",
"calories": 14
}
Request:
DELETE /api/v1/foods/:id
Content-Type: application/json
Accept: application/json
Response:
status: 204
Request:
GET /api/v1/meals
Content-Type: application/json
Accept: application/json
Response:
[
{
"id": 1,
"name": "Breakfast",
"foods": [
{
"id": 1,
"name": "Banana",
"calories": 150
},
{
"id": 6,
"name": "Yogurt",
"calories": 550
},
{
"id": 12,
"name": "Apple",
"calories": 220
}
]
},
{
"id": 2,
"name": "Snack",
"foods": [
{
"id": 1,
"name": "Banana",
"calories": 150
},
{
"id": 9,
"name": "Gum",
"calories": 50
},
{
"id": 10,
"name": "Cheese",
"calories": 400
}
]
}
]
Request:
GET /api/v1/meals/:meal_id/foods
Content-Type: application/json
Accept: application/json
Response:
status: 200
body:
{
"id": 1,
"name": "Breakfast",
"foods": [
{
"id": 1,
"name": "Banana",
"calories": 150
},
{
"id": 6,
"name": "Yogurt",
"calories": 550
},
{
"id": 12,
"name": "Apple",
"calories": 220
}
]
}
Request:
POST /api/v1/meals/:meal_id/foods/:id
Content-Type: application/json
Accept: application/json
Response:
status: 201
body:
{
"message": "successfully added FOODNAME to MEALNAME"
}
Request:
DELETE /api/v1/meals/:meal_id/foods/:id
Content-Type: application/json
Accept: application/json
Response:
status: 204