@philippdormann/mensamax-api

MensaMax-API. Simple APIs for using MensaMax data in modern applications

Usage no npm install needed!

<script type="module">
  import philippdormannMensamaxApi from 'https://cdn.skypack.dev/@philippdormann/mensamax-api';
</script>

README

MensaMax-API

Scraper for MensaMax products (like mensadigital.de/ mensamax.de/ mensapoint.de)

🍲🥘🥡🍛🍜🦐🥔
🍴🍽️ this is just a fancy way of getting some food 🍽️🍴
🍲🥘🥡🍛🍜🦐🥔

Deployment donate with PayPal buy me a coffee ko-fi

🧐 Usage

General Note: Please use your own caching strategy, MensaMax servers might be quite slow

API usage

see https://mensa.vercel.app/institutions-ui for API URLs

npm package usage

Install package

yarn add @philippdormann/mensamax-api

ts/ module imports

import { fetcher, parser } from '@philippdormann/mensamax-api';
const html = await fetcher({ p: 'FO111', e: 'herz' });
const parsed = await parser(html);
console.log(parsed);

CommonJS imports

const { fetcher, parser } = require('@philippdormann/mensamax-api');
(async function() {
    try {
        const html = await fetcher({ p: 'FO111', e: 'herz' });
        const parsed = await parser(html);
        console.log(parsed);
    } catch (e) {
        console.log(e);
    }
})();

🚀 Deployment

This project is deployed as a serverless function on the url https://mensa.vercel.app with Vercel ☁️

🐳 Docker Deployment

This project can be deployed as a docker container. To do so, just run this code:

docker-compose up -d --build

💻 Local Development

Either develop on your machine directly or use the provided devcontainer for VSCode

yarn && yarn dev

💡 How this works

  1. Fetch data from url (fetcher.js)
    • fetch VIEWSTATE + VIEWSTATEGENERATOR from .NET with axios
      • hit login endpoint with a GET request
      • request method: POST
      • enable followAllRedirects
      • set login headers
    • setup request (these settings are important)
      • enable cookies
      • request method: POST
      • enable followAllRedirects
      • set login headers
  2. Parsing the data (parser.js)
    • get relevant elements with cheerio
      • timePeriod
      • categories
      • day cards with food items
    • minify html
    • Regex
    • Replace unreadable markup such as internal MensaMax IDs
    • Build JSON from custom markup
  3. Serve via Express/ Vercel Serverless Function

🏫 Known/ tested institutions

🧠 General Knowledge

  • For some reason, MensaMax IT department decided to have many URLs
  • These URLs are not interchangeable and seem to be different MensaMax versions (as of 25.06.2021)
  • There is a private/ internal GraphQL API for MensaMax which needs authentication

👍💰 Support this project

You like this project and would like to give something back? Thanks! Have a look at my profile for more information & options.