Git Product home page Git Product logo

inst377-lab-work's Introduction

INST377 Lab Support Software

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.

Getting Started

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

Install Dependencies

npm install

Run the Server

npm start

Below are details of the API contained within this piece of labwork.


REST API example using Sequelize

Method Action
GET Retrieves resources
POST Creates resources
PUT Changes and/or replaces resources or collections
DELETE Deletes resources

Dining Hall

Get list of Dining Halls

Request

GET /api/dining

curl http://localhost:3000/api/dining

Response

[{
        "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 a Specific Dining Hall

Request

GET /api/dining/:hall_id

curl http://localhost:3000/api/dining/1

Response

[{
    "hall_id":1,
    "hall_name":"North Campus Dining Hall",
    "hall_location":"North Campus"
}]

Create a new Dining Hall

Request

POST /api/dining

curl -d "hall_id=4&hall_name=Example&hall_location=Hornbake" -X POST http://localhost:3000/api/dining

Response

{
    "hall_id":"4",
    "hall_name":"Example",
    "hall_location":"Hornbake"
}

Updating an Existing Dining Hall

Request

PUT /api/dining

curl -d "hall_id=4&hall_name=Example1&hall_location=Stamp" -X PUT http://localhost:3000/api/dining

Response

Successfully Updated

Delete an Existing Dining Hall

Request

DELETE /api/dining/:hall_id

curl -X DELETE http://localhost:3000/api/dining/4

Response

Successfully Deleted

Meals

Get list of Meals

Request

GET /api/meals

curl http://localhost:3000/api/meals

Response

[{
    "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 a Specific Meal

Request

GET /api/meals/:meal_id

curl http://localhost:3000/api/meals/1

Response

[{
    "meal_id":1,
    "meal_name":"Scrambled Eggs",
    "meal_category":"B"
}]

Updating an Existing Meal

Request

PUT /api/meals

curl -d "meal_id=1&meal_name=Scrambled Eggs&meal_category=L" -X PUT http://localhost:3000/api/meal

Response

Successfully Updated

Macros

Get list of Macros

Request

GET /api/macros

curl http://localhost:3000/api/macros

Response

[{
    "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 a Macros for a Specific Meal

Request

GET /api/macros/:meal_id

curl http://localhost:3000/api/macros/1

Response

[{
    "macro_id":1,
    "calories":218,
    "serving_size":20,
    "cholesterol":544,
    "sodium":206,
    "carbs":1,
    "protein":17,
    "meal_id":1,
    "fat":16
}]

Updating an Existing Macro

Request

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

Response

Successfully Updated

Custom Client SQL

Request

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`)'   

Response

[{
    "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
},
    ...
]

inst377-lab-work's People

Contributors

aleitch1 avatar mac5617 avatar shivppatel avatar krithikabalasubramanian 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.