Studierendenwerk Mainz Menu API

PHP 7.4+ JSON REST API

This API provides access to the current menu data from all Studierendenwerk Mainz cafeterias and dining halls. It scrapes the official website and returns the data in a clean, structured JSON format, organized by days and locations.

🚀 Quick Start

Installation

  1. Clone this repository to your web server
  2. Ensure PHP 7.4 or higher is installed
  3. Copy the menu.php file to your desired location
  4. Make sure your server has permission to make outbound HTTP requests

Basic Usage

GET https://your-domain.com/menu.php?display_type=1

📖 API Documentation

Endpoints

Parameter Values Description
display_type 1, 2, or 3
  • 1 = Today's menu (single day)
  • 2 = Current week (multiple days)
  • 3 = Next week (multiple days)

Response Format

{
  "meta": {
    "display_type": 1,
    "timestamp": 1704636789
  },
  "days": [
    {
      "date": "2025-01-07",
      "locations": [
        {
          "name": "Zentralmensa",
          "closed": false,
          "meals": [
            {
              "name": "Meal name",
              "price_student": 3.58,
              "price_staff": 5.93,
              "attributes": [
                "vegetarian",
                "climate_friendly",
                "contains_gluten"
              ],
              "co2_value": 1569
            }
          ]
        }
      ]
    }
  ]
}

Response Fields

Field Type Description
meta.display_type integer The requested display type (1, 2, or 3)
meta.timestamp integer Unix timestamp of when the response was generated
days array Array of day objects, each containing locations and their menus
days[].date string ISO 8601 formatted date (YYYY-MM-DD)
days[].locations array Array of locations available on this date
location.name string Name of the dining location
location.closed boolean Whether the location is closed on this date
location.meals array Array of meal objects available at this location

Meal Attributes

Attribute Description
vegan Meal is vegan
vegetarian Meal is vegetarian
climate_friendly Meal is climate-friendly
contains_gluten Contains gluten
contains_lactose Contains lactose
contains_fish Contains fish
contains_pork Contains pork
contains_beef Contains beef
contains_chicken Contains chicken

📝 Examples

Fetch Today's Menu

curl "https://your-domain.com/menu.php?display_type=1"

Fetch Current Week

curl "https://your-domain.com/menu.php?display_type=2"

Fetch Next Week

curl "https://your-domain.com/menu.php?display_type=3"

JavaScript Example

async function getMenu(displayType = 1) {
    const response = await fetch(`https://your-domain.com/menu.php?display_type=${displayType}`);
    const data = await response.json();
    
    // Access first day's data
    const firstDay = data.days[0];
    console.log(`Menu for ${firstDay.date}:`, firstDay.locations);
    
    // Example: Get all open locations for a specific day
    const openLocations = firstDay.locations
        .filter(location => !location.closed)
        .map(location => location.name);
    
    // Example: Get all vegan meals from all locations
    const veganMeals = firstDay.locations
        .flatMap(location => location.meals)
        .filter(meal => meal.attributes?.includes('vegan'));
    
    return data;
}

⚠️ Notes

Important:

🔒 CORS

The API includes CORS headers and allows requests from any origin. If you need to restrict access, modify the following line in menu.php:

header('Access-Control-Allow-Origin: *');

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.