GitHunt
MA

martinkr/golem-api-programmierung

Codebeispiele zum Special "API Programmierung"

mit-maschinen-kommunizieren

This folder contains several small example servers that demonstrate different API styles for a simple "menu" service (REST, GraphQL, gRPC, MQTT, SOAP). The code is intentionally minimal and meant for learning or small local experiments.

Contents

  • graphql/ — GraphQL demo (includes graphql.server.mjs, menu.server.mjs, waiter.server.mjs)
  • grpc/ — gRPC demo (includes grpc.server.mjs, menu.proto, menu.server.mjs, waiter.server.mjs)
  • intro/ — small REST/demo servers (includes menu.server.mjs, waiter.server.mjs)
  • mqtt/, rest/, soap/ — placeholders or additional demos
  • test-apis.sh — convenience script to exercise the example APIs
  • package.json — top-level npm metadata (some demos may have their own package.json)

Quick start

  1. From this directory, install dependencies (if needed):
cd "mit-maschinen-kommunizieren copy"
npm install
  1. Run one of the example servers (files are ESM .mjs) — examples:
# REST intro demo
node intro/waiter.server.mjs

# GraphQL demo
node graphql/graphql.server.mjs

# gRPC demo (may start both server and waiter proxy)
node grpc/grpc.server.mjs
  1. Use the included test-apis.sh to run a quick smoke-check against the examples:
./test-apis.sh

API Examples

Once a server is running, try these example calls from another terminal:

REST / Intro demo

Start with: node intro/waiter.server.mjs (typically runs on http://localhost:3000)

# Get the full menu
curl http://localhost:3000/menu

# Query the menu with a filter maxPrice
curl "http://localhost:3000/menu?maxPrice=5"

# Query the vegetarian menu 
curl "http://localhost:3000/menu/vegetarian"

GraphQL demo

Start with: node graphql/graphql.server.mjs (typically runs on http://localhost:4000/graphql)

# Query via curl (or use GraphQL Playground in the browser)
curl -X POST http://localhost:4000/graphql \
  -H "Content-Type: application/json" \
  -d '{"query":"{ menu { name vegetarian } }"}'

gRPC demo

Start with: node grpc/grpc.server.mjs (typically runs on localhost:50051)

Use a gRPC client tool like grpcurl:

# List available services
grpcurl -plaintext localhost:50051 list

# Call a menu RPC
grpcurl -plaintext localhost:50051 menu.Menu/GetMenu

MQTT demo

If available, start with: node mqtt/mqtt.server.mjs

Use an MQTT client like mosquitto_pub / mosquitto_sub:

# Subscribe to menu updates
mosquitto_sub -h localhost -t "menu/#"

# Publish a menu request (in another terminal)
mosquitto_pub -h localhost -t "menu/request" -m "get"

Notes

  • These scripts use .mjs ESM modules — use a modern Node.js (16+) that supports ESM.
  • Some subfolders have their own package.json; npm install there may be required for demo-specific dependencies.
  • test-apis.sh may need execute permission: chmod +x test-apis.sh.
  • Default ports may vary — check server output for the actual port and endpoint.
  • This repository is for demo/learning purposes; review configs before reusing in production.

Languages

JavaScript91.1%Shell8.9%

Contributors

Created September 28, 2025
Updated February 18, 2026