Dining API

CS50’s Dining API provides programmatic access via HTTP to data from Harvard University Dining Services (HUDS), including menus for undergraduate dining halls, graduate dining halls, and some cafes on campus. The API provides endpoints for:

Categories

Getting Categories

GET /dining/categories
Synopsis

Returns a JSON array of objects, each of which represents a category of food. For example, https://api.cs50.io/dining/categories.

Status Codes
Response JSON Array of Objects
  • id (integer) – A category’s unique identifer. Usable as a primary key in a databse.

  • name (string) – A category’s name.

Example: Getting All Categories

https://api.cs50.io/dining/categories

import requests

# Get categories
response = requests.get("https://api.cs50.io/dining/categories")

# Convert JSON to list of dicts
categories = response.json()

# Print each category's name
for category in categories:
    print(category["name"])

Getting a Category

GET /dining/categories/(id)
Synopsis

Returns a JSON object that represents a category, where id is that category’s unique identifier. For example, https://api.cs50.io/dining/categories/32 represents Fresh Fruit, whereas https://api.cs50.io/dining/categories/62 represents Daily Soups. Yum!

Parameters
  • id – A location’s unique identifier.

Status Codes
  • 200 OK – Returned if a category with id exists.

  • 404 Not Found – Returned if no category with id exists.

Response JSON Object
  • id (integer) – A category’s unique identifer. Usable as a primary key in a databse.

  • name (string) – A category’s name.

Example: Getting Fresh Fruit

https://api.cs50.io/dining/categories/32

import requests

# Get category
response = requests.get("https://api.cs50.io/dining/categories/32")

# Convert JSON to dict
category = response.json()

# Print category's name
print(category["name"])

Locations

Getting Locations

GET /dining/locations
Synopsis

Returns a JSON array of objects, each of which represents a location. For example, https://api.cs50.io/dining/locations.

Status Codes
Response JSON Array of Objects
  • id (integer) – A location’s unique identifer. Usable as a primary key in a databse.

  • name (string) – A location’s name.

Example: Getting All Locations

https://api.cs50.io/dining/locations

import requests

# Get locations
response = requests.get("https://api.cs50.io/dining/locations")

# Convert JSON to list of dicts
locations = response.json()

# Print each location's name
for location in locations:
    print(location["name"])

Getting a Location

GET /dining/locations/(id)
Synopsis

Returns a JSON object that represents a location, where id is that location’s unique identifier. For example, https://api.cs50.io/dining/locations/30 represents Annenberg Hall, while https://api.cs50.io/dining/locations/7 represents Dunster and Mather House. Because some dining halls (e.g., Dunster’s and Mather’s) share kitchens (and thus menus), they also share an id (and name) in the API.

Parameters
  • id – A location’s unique identifier.

Status Codes
  • 200 OK – Returned if a location with id exists.

  • 404 Not Found – Returned if no location with id exists.

Response JSON Object
  • id (integer) – A location’s unique identifer. Usable as a primary key in a databse.

  • name (string) – A location’s name.

Example: Getting Annenberg Hall

https://api.cs50.io/dining/locations/7

import requests

# Get location
response = requests.get("https://api.cs50.io/dining/locations/30")

# Convert JSON to dict
location = response.json()

# Print location's name
print(location["name"])

Recipes

Getting Recipes

GET /dining/recipes
Synopsis

Returns a JSON array of objects, each of which represents a recipe. For example, https://api.cs50.io/dining/recipes.

Status Codes
Response JSON Array of Objects
  • id (integer) – A recipe’s unique identifer. Usable as a primary key in a databse.

  • name (string) – A recipe’s name.

Example: Getting All Recipes

https://api.cs50.io/dining/recipes

import requests

# Get categories
response = requests.get("https://api.cs50.io/dining/recipes")

# Convert JSON to list of dicts
recipes = response.json()

# Print each recipe's name
for recipe in recipes:
    print(recipe["name"])

Getting a Recipe

GET /dining/recipes/(id)
Synopsis

Returns a JSON object that represents a recipe, where id is that recipe’s unique identifier. For example, https://api.cs50.io/dining/recipes/22011 represents Kabocha Squash Soup, whereas https://api.cs50.io/dining/recipes/22045 represents Wheat Tortillas. Yum!

Parameters
  • id – A recipe’s unique identifier.

Status Codes
  • 200 OK – Returned if a recipe with id exists.

  • 404 Not Found – Returned if no recipe with id exists.

Response JSON Object
  • id (integer) – A recipe’s unique identifer. Usable as a primary key in a databse.

  • name (string) – A recipe’s name.

Example: Getting Kabocha Squash Soup

https://api.cs50.io/dining/recipes/22011

import requests

# Get recipe
response = requests.get("https://api.cs50.io/dining/recipes/22011")

# Convert JSON to dict
recipe = response.json()

# Print recipe's name
print(recipe["name"])

Acknowledgements

Special thanks to CS50’s friends at HUDS and HUIT for this API’s data!