api
from corio import api
api provides a lightweight FastAPI base where endpoints are defined as dataclass configuration.
Main pieces:
Endpoint: endpoint metadata + target methodBase: app bootstrap, endpoint registration, child API mounting, and uvicorn launch helpers
Install:
pip install "corio[api]" --upgrade
Typical Endpoint Pattern
from corio import api
class HealthApi(api.Base):
TITLE = "Health API"
def get_endpoints(self):
return [
api.Endpoint(method_http=self.app.get, path="/health", method=self.health, tags="status"),
]
async def health(self):
"""Service health."""
return {"ok": True}
Run with:
HealthApi.launch()
Real-World Usage Pattern (generalized)
Sibling repos commonly:
- subclass
api.Base - keep endpoint list in
get_endpoints() - attach tags per feature area (
cache,blocking,documents, etc.) - mount child APIs using
childrenwhen composing a larger API surface
Notes
Baseinstruments FastAPI viacorio.logs.- In dev mode, exception handling is configured to re-raise for easier debugging.
- Default endpoint method is POST unless
method_httpis set.