Menu
Introduction
Getting Started
Developer guide
Release
Architecture
CLI
Technical documentations
Version
Publication date

Mar 9, 2022

Confidentiality
Public
Reactions
1
Share

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. Pass with_exception_handlers=True to add the standard exception handlers automatically.

  • register_brick_app(brick_name, ...) -- convenience wrapper that calls register_api with path /brick/{brick_name}/ and with_exception_handlers=True by 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"}
Functions
clear @classmethod

Clear all registered apis. Useful for tests.

configure_exception_handlers @classmethod

Add standard exception handlers to a FastAPI app.

Adds handlers for HTTPException, RequestValidationError, and generic Exception using the standard ExceptionHandler.

app : FastAPI
get_all_apis @classmethod

Return all registered apis.

Return type : dict
get_brick_api_path @classmethod

Get the mount path for a registered brick API.

brick_name : str
The brick name
Return type : str
register_api @classmethod

Create and register a FastAPI sub-app at the given mount path.

path : str
The mount path (e.g. "/core-api/" or "/s3-server/")
docs_url : str | None
The docs_url passed to FastAPI (None to disable docs)
with_exception_handlers : bool - True
If True, add the standard exception handlers (HTTPException, RequestValidationError, generic Exception)
Return type : FastAPI
register_brick_api @classmethod

Create 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.

brick_name : str
The brick name (used as route prefix)
docs_url : str | None - /docs
The docs_url passed to FastAPI (default "/docs")
with_exception_handlers : bool - True
If True (default), add the standard exception handlers
Return type : FastAPI
Shine Logo
Technical bricks to reuse or customize

Have you developed a brick?

Share it to accelerate projects for the entire community.