Die MySQL-Datenbank und die Slim-REST-API sind eingerichtet und getestet.
Datenbank nerdshop (MAMP, Port 8889) enthält die Tabelle products mit den 13 Einträgen aus der JSON-Datei. Die Mongo-IDs bleiben als id erhalten; die API liefert sie als _id, damit die React-App kompatibel bleibt.
API läuft auf http://localhost:8080
Authentifizierung erfolgt per JWT (firebase/php-jwt, HS256). Login liefert ein Bearer-Token; geschützte Routen erwarten Authorization: Bearer <token>.
| Methode | URL | Auth | Status |
|---|---|---|---|
POST |
/login |
nein | JWT + User |
POST |
/logout |
ja | Session Ende |
GET |
/me |
ja | aktueller User |
GET |
/users |
ja | alle User |
GET |
/users/{id} |
ja | ein User |
GET |
/products |
nein | alle Produkte |
GET |
/products/{id} |
nein | ein Produkt |
POST |
/products |
ja | anlegen |
PUT |
/products/{id} |
ja | aktualisieren |
PATCH |
/products/{id} |
ja | teilweise |
DELETE |
/products/{id} |
ja | löschen |
Login-Beispiel:
curl -s -X POST http://localhost:8080/login \
-H 'Content-Type: application/json' \
-d '{"username":"megaman","password":"<passwort>"}'
Antwort: { "user": { ... }, "token": "<jwt>" }. Anschließend:
curl -s http://localhost:8080/users \
-H "Authorization: Bearer <jwt>"
JWT_SECRET und JWT_TTL (Sekunden, Standard 86400) stehen in .env. CORS ist für http://localhost:5173 (Vite) gesetzt, inklusive Header Authorization.
Server neu starten:
cd slim-php-framework
php -S localhost:8080 -t public public/router.php
Falls MAMP andere Zugangsdaten nutzt, stehen sie in slim-php-framework/.env.