ApiRegistry
Registry that creates and stores FastAPI sub-apps. Each registered app will be mounted on the main app at the specified path.
Registration methods:
register_api(path, ...)-- creates a FastAPI app at the given mount path. Passwith_exception_handlers=Trueto add the standard exception handlers automatically. Passsilent_access_log=Trueto downgrade access logs for this path to DEBUG level.register_brick_app(brick_name, ...)-- convenience wrapper that callsregister_apiwith path/brick/{brick_name}/andwith_exception_handlers=Trueby default.configure_exception_handlers(app)-- public helper that adds the three standard exception handlers (HTTPException, RequestValidationError, generic Exception) to any FastAPI app.
Usage from an external brick::
from gws_core import ApiRegistry
eln_app = ApiRegistry.register_brick_api("gws_eln")
@eln_app.get("/my-route")
def my_route():
return {"hello": "world"}
Clear all registered apis. Useful for tests.
Add standard exception handlers to a FastAPI app.
Adds handlers for HTTPException, RequestValidationError, and generic Exception using the standard ExceptionHandler.
The generic Exception handler's responses never traverse the app's middleware (they are produced above it, by ServerErrorMiddleware), so the headers the app's middleware would have set are stamped manually — hence the two parameters below, which must mirror the app's middleware setup.
FastAPIgws_core.core.classes.cors_config.CorsPolicy | Nonebool - TrueReturn all registered apis.
dictGet the mount path for a registered brick API.
strstrInstall the access log filter on uvicorn's access logger.
Downgrades log entries to DEBUG for all paths registered with
silent_access_log=True. Call this before uvicorn.run().
Create and register a FastAPI sub-app at the given mount path.
strstr | Nonebool - Truebool - Truebool - Falsegws_core.core.classes.cors_config.CorsPolicy | NoneFastAPICreate and register a FastAPI sub-app for an external brick.
The app is mounted at /brick/{brick_name}/ and has the standard
exception handlers automatically configured by default.
strstr | None - /docsbool - Truebool - Truegws_core.core.classes.cors_config.CorsPolicy | NoneFastAPI