Spaces:
Sleeping
Sleeping
FastAPI: friendly root route at GET / (was 404)
Browse filesAdds a JSON service descriptor listing the available endpoints and
linking to the auto-generated OpenAPI docs at /docs and /redoc. The
404 at root was correct but unhelpful when someone visits the Render
URL in a browser. All five API tests still pass.
- src/cdpr/interface/api.py +26 -0
src/cdpr/interface/api.py
CHANGED
|
@@ -98,6 +98,32 @@ def _serialise_result(result: "SimulationResult") -> dict[str, object]:
|
|
| 98 |
# Endpoints
|
| 99 |
# ---------------------------------------------------------------------------
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
@app.get("/health")
|
| 102 |
def health() -> dict[str, str]:
|
| 103 |
return {"status": "ok"}
|
|
|
|
| 98 |
# Endpoints
|
| 99 |
# ---------------------------------------------------------------------------
|
| 100 |
|
| 101 |
+
@app.get("/")
|
| 102 |
+
def root() -> dict[str, object]:
|
| 103 |
+
"""Service descriptor returned when the root URL is hit in a browser.
|
| 104 |
+
|
| 105 |
+
Lists the available endpoints + points the visitor at the OpenAPI
|
| 106 |
+
docs. The actual API surface is the other ``@app.<method>`` routes
|
| 107 |
+
below --- this is a friendly landing page, not the API itself.
|
| 108 |
+
"""
|
| 109 |
+
return {
|
| 110 |
+
"name": "cdpr",
|
| 111 |
+
"version": app.version,
|
| 112 |
+
"summary": app.summary,
|
| 113 |
+
"endpoints": {
|
| 114 |
+
"health": "GET /health",
|
| 115 |
+
"robots": "GET /robots",
|
| 116 |
+
"simulate": "POST /simulate",
|
| 117 |
+
"workspace": "POST /workspace",
|
| 118 |
+
"plot": "POST /plot",
|
| 119 |
+
"openapi": "GET /openapi.json",
|
| 120 |
+
"swagger_ui": "GET /docs",
|
| 121 |
+
"redoc": "GET /redoc",
|
| 122 |
+
},
|
| 123 |
+
"repository": "https://github.com/Tachia/cdpr_simulator",
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
|
| 127 |
@app.get("/health")
|
| 128 |
def health() -> dict[str, str]:
|
| 129 |
return {"status": "ok"}
|