How it Works¶
Adding Routes, Routers, and Events¶
The msdss_base_api.core.API
wraps around FastAPI to define routes and logic, while Uvicorn is used to serve the APIs programmatically.
First a FastAPI()
object is created, and routes/routers are added with .add_api_route() / .include_router(), while API events are handled with .add_event_handler().
Then uvicorn
is used to run the app with .run().
These form the basis of adding routes, routers, and events.
![digraph methods1 {
rankdir=TB;
api[label="FastAPI" URL="https://fastapi.tiangolo.com/" style=filled];
apiroutemeth[label=".add_api_route()" shape=rect style=rounded];
eventhandlermeth[label=".add_event_handler()" shape=rect style=rounded];
routermeth[label=".add_event_handler()" shape=rect style=rounded];
server[label="Uvicorn" URL="https://www.uvicorn.org/" style=filled];
run[label=".run()" shape=rect style=rounded];
start[label=".start()" shape=rect style=rounded];
addevent[label=".add_event()" shape=rect style=rounded];
addroute[label=".add_route()" shape=rect style=rounded];
addrouter[label=".add_router()" shape=rect style=rounded];
subgraph cluster {
label=< <B>msdss-base-api.core.API (add_route/router/event)</B> >;
style=rounded;
{rank=min; api -> server;}
apiroutemeth -> api[arrowhead=none];
routermeth -> api[arrowhead=none];
eventhandlermeth -> api[arrowhead=none];
run -> server[arrowhead=none];
apiroutemeth -> addroute;
routermeth -> addrouter;
eventhandlermeth -> addevent;
run -> start;
}
}](_images/graphviz-5f15f28e4c97bcf4a9117a084bf14ca698aab754.png)
For more information on adding routes, routers, and events, see:
Combining Routes, Routers, and Events Across Apps¶
When adding routes, routers, and events, the arguments are tracked in attributes routes
, routers
, and events
, which are then
used to combine routes, routers, and events from other app instances.
![digraph methods2 {
rankdir=TB;
addevent[label=".add_event()" shape=rect style=rounded];
addroute[label=".add_route()" shape=rect style=rounded];
addrouter[label=".add_router()" shape=rect style=rounded];
addapp[label=".add_apps()" shape=rect style=rounded];
appevents[label=".add_app_events()" shape=rect style=rounded];
approutes[label=".add_app_routes()" shape=rect style=rounded];
approuters[label=".add_app_routers()" shape=rect style=rounded];
eventattr[label=".events" shape=plain style=rounded];
routeattr[label=".routes" shape=plain style=rounded];
routerattr[label=".routers" shape=plain style=rounded];
subgraph cluster {
label=< <B>msdss-base-api.core.API (add_app_events/routes/routers)</B> >;
style=rounded;
addevent -> eventattr -> appevents -> addapp;
addroute -> routeattr -> approutes -> addapp;
addrouter -> routerattr -> approuters -> addapp;
}
}](_images/graphviz-d5b8b2a0fdad96f14cbb3a82cea321c13acdb8a2.png)
For more information on combining app routes, routers, and events, see: