REST API-Nutzung wird im Dashboard ausgewertet und dokumentiert
This commit is contained in:
174
README.md
174
README.md
@@ -18,6 +18,180 @@ Datumsrechner Live: [https://date.elpatron.me](https://date.elpatron.me)
|
||||
- Start-/Enddatum einer Kalenderwoche eines Jahres
|
||||
- Statistik-Dashboard mit Passwortschutz unter `/stats`
|
||||
|
||||
## REST API
|
||||
|
||||
Alle Datumsfunktionen stehen auch als REST-API zur Verfügung. Die API akzeptiert und liefert JSON.
|
||||
**Basis-URL:** `http://localhost:5000/api/`
|
||||
|
||||
**Hinweis:** Die Nutzung der REST API wird im Statistik-Dashboard ausgewertet und als Diagramm angezeigt.
|
||||
|
||||
### Endpunkte und Beispiele
|
||||
|
||||
#### 1. Tage/Werktage zwischen zwei Daten
|
||||
|
||||
**POST** `/api/tage_werktage`
|
||||
|
||||
```json
|
||||
{
|
||||
"start": "2024-06-01",
|
||||
"end": "2024-06-10",
|
||||
"werktage": true
|
||||
}
|
||||
```
|
||||
|
||||
**Mit curl:**
|
||||
```bash
|
||||
curl -X POST http://localhost:5000/api/tage_werktage \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"start": "2024-06-01", "end": "2024-06-10", "werktage": true}'
|
||||
```
|
||||
|
||||
**Antwort:**
|
||||
```json
|
||||
{ "result": 7 }
|
||||
```
|
||||
|
||||
#### 2. Wochentag zu einem Datum
|
||||
|
||||
**POST** `/api/wochentag`
|
||||
|
||||
```json
|
||||
{ "datum": "2024-06-10" }
|
||||
```
|
||||
|
||||
**Mit curl:**
|
||||
```bash
|
||||
curl -X POST http://localhost:5000/api/wochentag \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"datum": "2024-06-10"}'
|
||||
```
|
||||
|
||||
**Antwort:**
|
||||
```json
|
||||
{ "result": "Montag" }
|
||||
```
|
||||
|
||||
#### 3. Kalenderwoche zu Datum
|
||||
|
||||
**POST** `/api/kw_berechnen`
|
||||
|
||||
```json
|
||||
{ "datum": "2024-06-10" }
|
||||
```
|
||||
|
||||
**Mit curl:**
|
||||
```bash
|
||||
curl -X POST http://localhost:5000/api/kw_berechnen \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"datum": "2024-06-10"}'
|
||||
```
|
||||
|
||||
**Antwort:**
|
||||
```json
|
||||
{ "result": "KW 24 (2024)", "kw": 24, "jahr": 2024 }
|
||||
```
|
||||
|
||||
#### 4. Start-/Enddatum einer Kalenderwoche
|
||||
|
||||
**POST** `/api/kw_datum`
|
||||
|
||||
```json
|
||||
{ "jahr": 2024, "kw": 24 }
|
||||
```
|
||||
|
||||
**Mit curl:**
|
||||
```bash
|
||||
curl -X POST http://localhost:5000/api/kw_datum \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"jahr": 2024, "kw": 24}'
|
||||
```
|
||||
|
||||
**Antwort:**
|
||||
```json
|
||||
{
|
||||
"result": "10.06.2024 bis 16.06.2024",
|
||||
"start": "2024-06-10",
|
||||
"end": "2024-06-16"
|
||||
}
|
||||
```
|
||||
|
||||
#### 5. Datum plus/minus Tage, Wochen, Monate
|
||||
|
||||
**POST** `/api/plusminus`
|
||||
|
||||
```json
|
||||
{
|
||||
"datum": "2024-06-10",
|
||||
"anzahl": 5,
|
||||
"einheit": "tage",
|
||||
"richtung": "add",
|
||||
"werktage": false
|
||||
}
|
||||
```
|
||||
|
||||
**Mit curl:**
|
||||
```bash
|
||||
curl -X POST http://localhost:5000/api/plusminus \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"datum": "2024-06-10", "anzahl": 5, "einheit": "tage", "richtung": "add", "werktage": false}'
|
||||
```
|
||||
|
||||
**Antwort:**
|
||||
```json
|
||||
{ "result": "2024-06-15" }
|
||||
```
|
||||
|
||||
**Hinweis:**
|
||||
- `"einheit"`: `"tage"`, `"wochen"` oder `"monate"`
|
||||
- `"richtung"`: `"add"` (plus) oder `"sub"` (minus)
|
||||
- `"werktage"`: `true` für Werktage, sonst `false` (nur bei `"tage"` unterstützt)
|
||||
|
||||
#### 6. Statistik
|
||||
|
||||
**GET** `/api/stats`
|
||||
|
||||
**Mit curl:**
|
||||
```bash
|
||||
curl http://localhost:5000/api/stats
|
||||
```
|
||||
|
||||
**Antwort:**
|
||||
```json
|
||||
{
|
||||
"pageviews": 42,
|
||||
"func_counts": { "plusminus": 10, "tage_werktage": 5 },
|
||||
"impressions_per_day": { "2024-06-10": 7 }
|
||||
}
|
||||
```
|
||||
|
||||
#### 7. Monitoring & Healthcheck
|
||||
|
||||
**GET** `/api/monitor`
|
||||
|
||||
**Mit curl:**
|
||||
```bash
|
||||
curl http://localhost:5000/api/monitor
|
||||
```
|
||||
|
||||
**Antwort:**
|
||||
```json
|
||||
{
|
||||
"status": "ok",
|
||||
"message": "App running",
|
||||
"time": "2025-07-24T13:37:00.123456",
|
||||
"uptime_seconds": 12345,
|
||||
"pageviews_last_7_days": 42
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**Fehlerfälle** liefern immer einen HTTP-Statuscode 400 und ein JSON mit `"error"`-Feld, z.B.:
|
||||
|
||||
```json
|
||||
{ "error": "Ungültige Eingabe", "details": "..." }
|
||||
```
|
||||
|
||||
## Installation (lokal)
|
||||
|
||||
1. Python 3.8+ installieren
|
||||
|
Reference in New Issue
Block a user