dso_api.dynamic_api.routers module

The router logic is the core of the dynamic API creation.

When the call to initialize() is made, all viewsets, models, serializers, filtersets and so on are created. This fills the complete router so calling router.urls returns all endpoints as if they were hard-coded. The router can be used in the urls.py file like:

router = DynamicRouter()
router.initialize()

urlpatterns = [
    path("/some/path/", include(router.urls)),
]

The initialize() function is also responsible for calling the model_factory(), viewset_factory() and remote_viewset_factory() functions.

class dso_api.dynamic_api.routers.DynamicAPIIndexView(**kwargs)

Bases: APIIndexView

An overview of API endpoints.

Get list of other APIs exposing the same dataset

class dso_api.dynamic_api.routers.DynamicRouter

Bases: DefaultRouter

Router that dynamically creates all views and viewsets based on the Dataset models.

__init__()
clear_urls()

Internal function for tests, restore the internal registry.

get_api_root_view(api_urls=None)

Show the OpenAPI specification as root view.

get_urls()

Add extra URLs beside the registered viewsets.

initialize()

Initialize all dynamic routes on startup.

The initialization is skipped when INITIALIZE_DYNAMIC_VIEWSETS is set, or when the meta tables are not found in the database (e.g. using a first migrate).

The initialization calls the model_factory(), viewset_factory() and remote_viewset_factory() functions.

is_initialized() bool

Tell whether the router initialization was used to create viewsets.

register(prefix, viewset, basename=None)

Overwritten function to preserve any manually added routes on reloading.

reload() dict[type[DynamicModel], str]

Regenerate all viewsets for this router.