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=info
Start:
docker compose up -d --build
pip install -r requirements.txt
python asgi.py
Service URLs:
- Swagger UI: http://localhost:8000/
- Health: http://localhost:8000/healthz
- If
MOODLE_URL
is unset or*
, includemoodle_url
in the query. - If
MOODLE_URL
is a real URL,moodle_url
is 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-URL
andX-Moodle-Direct-Method
for 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_url
per 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
,description
responses
: Optional OpenAPI response metadata
- Python (see
requirements.txt
) - Docker (optional)
MIT. See LICENSE
.
Made with ❤️ by MyDrift