This repository is the starting point for most labs in INST377. It represents a working "server" and "client" package for your first seven weeks of class. You can use any of the code you find here to help you with your labs or your group projects.
- "Clone" or download this repository using the large green button marked "code"
- Install the software dependencies
- Start your server, which will run on
port 3000
locally
npm install
npm start
Below are details of the API contained within this piece of labwork.
Method | Action |
---|---|
GET | Retrieves resources |
POST | Creates resources |
PUT | Changes and/or replaces resources or collections |
DELETE | Deletes resources |
GET /api/dining
curl http://localhost:3000/api/dining
[{
"hall_id":1,
"hall_name":"North Campus Dining Hall",
"hall_location":"North Campus"
},
{
"hall_id":2,
"hall_name":"South Campus Dining Hall",
"hall_location":"South Campus"
},
{
"hall_id":3,
"hall_name":"251 North Dining Hall",
"hall_location":"North Campus"
}]
GET /api/dining/:hall_id
curl http://localhost:3000/api/dining/1
[{
"hall_id":1,
"hall_name":"North Campus Dining Hall",
"hall_location":"North Campus"
}]
POST /api/dining
curl -d "hall_id=4&hall_name=Example&hall_location=Hornbake" -X POST http://localhost:3000/api/dining
{
"hall_id":"4",
"hall_name":"Example",
"hall_location":"Hornbake"
}
PUT /api/dining
curl -d "hall_id=4&hall_name=Example1&hall_location=Stamp" -X PUT http://localhost:3000/api/dining
Successfully Updated
DELETE /api/dining/:hall_id
curl -X DELETE http://localhost:3000/api/dining/4
Successfully Deleted
GET /api/meals
curl http://localhost:3000/api/meals
[{
"meal_id":1,
"meal_name":"Scrambled Eggs",
"meal_category":"B"
},
{
"meal_id":2,
"meal_name":"French Toast",
"meal_category":"B"
},
{
"meal_id":3,
"meal_name":"Pancakes",
"meal_category":"B"
},
...
]
GET /api/meals/:meal_id
curl http://localhost:3000/api/meals/1
[{
"meal_id":1,
"meal_name":"Scrambled Eggs",
"meal_category":"B"
}]
PUT /api/meals
curl -d "meal_id=1&meal_name=Scrambled Eggs&meal_category=L" -X PUT http://localhost:3000/api/meal
Successfully Updated
GET /api/macros
curl http://localhost:3000/api/macros
[{
"macro_id":1,
"calories":218,
"serving_size":20,
"cholesterol":544,
"sodium":206,
"carbs":1,
"protein":17,
"meal_id":1,
"fat":16
},
{
"macro_id":2,
"calories":371,
"serving_size":1,
"cholesterol":0,
"sodium":209,
"carbs":10,
"protein":5,
"meal_id":2,
"fat":10
},
...
]
GET /api/macros/:meal_id
curl http://localhost:3000/api/macros/1
[{
"macro_id":1,
"calories":218,
"serving_size":20,
"cholesterol":544,
"sodium":206,
"carbs":1,
"protein":17,
"meal_id":1,
"fat":16
}]
PUT /api/macros
curl -d "macro_id=1&calories=318&serving_size=20&cholesterol=544&sodium=206&carbs=1&protein=17&meal_id=1&fat=16" -X PUT http://localhost:3000/api/macros
Successfully Updated
GET /api/custom
curl --location --request GET 'http://localhost:3000/api/custom' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'query=SELECT
`DiningHall_Tracker`.`Meals`.`meal_name` AS `meal_name`,
`DiningHall_Tracker`.`Macros`.`calories` AS `calories`,
`DiningHall_Tracker`.`Macros`.`carbs` AS `carbs`,
`DiningHall_Tracker`.`Macros`.`sodium` AS `sodium`,
`DiningHall_Tracker`.`Macros`.`protein` AS `protein`,
`DiningHall_Tracker`.`Macros`.`fat` AS `fat`,
`DiningHall_Tracker`.`Macros`.`cholesterol` AS `cholesterol`
FROM
(`DiningHall_Tracker`.`Meals`
JOIN `DiningHall_Tracker`.`Macros`)
WHERE
(`DiningHall_Tracker`.`Meals`.`meal_id` = `DiningHall_Tracker`.`Macros`.`meal_id`)'
[{
"meal_name": "Scrambled Eggs",
"calories": 218,
"carbs": 1,
"sodium": 206,
"protein": 17,
"fat": 16,
"cholesterol": 544
},
{
"meal_name": "French Toast",
"calories": 371,
"carbs": 10,
"sodium": 209,
"protein": 5,
"fat": 10,
"cholesterol": 0
},
{
"meal_name": "Pancakes",
"calories": 430,
"carbs": 15,
"sodium": 111,
"protein": 4,
"fat": 15,
"cholesterol": 30
},
...
]