A FastAPI bridge that simplifies interaction with the Moodle API, providing discoverable endpoints and clear parameter guidelines. Built with FastAPI and Docker.
- Configuration-driven via
config.json - Dynamic FastAPI routes generated from config
- Built-in token retrieval endpoint
- Interactive API docs (Swagger UI)
- Docker-ready
Use the included compose.yaml or run the image directly.
Docker Compose (recommended):
services:
moodlewareapi:
build: .
ports:
- "8000:8000"
restart: unless-stopped
environment:
# Option A: Fixed Moodle URL for all requests
- MOODLE_URL=https://moodle.example.edu
# Option B: Per-request Moodle URL (set to * or leave empty)
# - MOODLE_URL=*
- ALLOW_ORIGINS=*
- LOG_LEVEL=infoStart:
docker compose up -d --buildpip install -r requirements.txt
python asgi.pyService URLs:
- Swagger UI: http://localhost:8000/
- Health: http://localhost:8000/healthz
- If
MOODLE_URLis unset or*, includemoodle_urlin the query. - If
MOODLE_URLis a real URL,moodle_urlis not required.
Example (per-request Moodle URL):
curl "http://localhost:8000/auth?moodle_url=https://moodle.school.edu&username=USER&password=PASS&service=moodle_mobile_app"Provide the token either via Authorization header or ?wstoken=.
Example using Authorization header (with preconfigured MOODLE_URL):
curl -H "Authorization: Bearer YOUR_TOKEN" "http://localhost:8000/core_webservice_get_site_info"Example using query parameter (with preconfigured MOODLE_URL):
curl "http://localhost:8000/core_webservice_get_site_info?wstoken=YOUR_TOKEN"Notes:
- When
ALLOW_ORIGINS=*, credentials are disabled per CORS spec. - Each response includes passthrough headers
X-Moodle-Direct-URLandX-Moodle-Direct-Methodfor debugging.
MOODLE_URL- Set to a full base URL (e.g.,
https://moodle.example.com) to use it for all requests, or - Set to
*or leave empty to requiremoodle_urlper request.
- Set to a full base URL (e.g.,
PORT(default 8000)ALLOW_ORIGINS(comma-separated;*allows all without credentials)LOG_LEVEL(critical|error|warning|info|debug, defaultinfo)
Minimal shape of an entry:
{
"path": "/core_webservice_get_site_info",
"method": "GET",
"function": "core_webservice_get_site_info",
"description": "Get Moodle site information & user information",
"tags": ["Core"],
"query_params": [
{
"name": "userid",
"type": "int",
"required": false,
"description": "User ID"
}
],
"responses": {
"200": {
"description": "OK"
}
}
}path: Path added under the Moodle base URLmethod: HTTP methodfunction: Moodle wsfunction name (auto-added for/webservice/rest/server.php)description,tags: For docs groupingquery_params: Parameter list withname,type(str|int|bool|float|double|list),required,default,descriptionresponses: Optional OpenAPI response metadata
- Python (see
requirements.txt) - Docker (optional)
MIT. See LICENSE.
Made with ❤️ by MyDrift
