File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed
Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -121,3 +121,31 @@ signature (their :func:`__init__` method).
121121
122122 flash_messages
123123 problem_details
124+
125+
126+ ReceiveRoutePlugin
127+ ------------------
128+
129+ :class: `~litestar.plugins.ReceiveRoutePlugin ` allows you to receive routes as they are registered on the application.
130+ This can be useful for plugins that need to perform actions based on the routes being added, such as generating
131+ documentation, validating route configurations, or tracking route statistics.
132+
133+ Implementations of this plugin must define a single method:
134+ :meth: `receive_route(self, route: BaseRoute) -> None: <litestar.plugins.ReceiveRoutePlugin.receive_route> `
135+
136+ The method receives a :class: `BaseRoute <litestar.routes.BaseRoute> ` instance as routes are registered on the application.
137+ This happens during the application initialization process, after routes are created but before the application starts.
138+
139+ Example
140+ +++++++
141+
142+ The following example shows a simple plugin that logs information about each route as it's registered:
143+
144+ .. code-block :: python
145+
146+ from litestar.plugins import ReceiveRoutePlugin
147+ from litestar.routes import BaseRoute
148+
149+ class RouteLoggerPlugin (ReceiveRoutePlugin ):
150+ def receive_route (self , route : BaseRoute) -> None :
151+ print (f " Route registered: { route.path} [ { ' , ' .join(route.http_methods)} ] " )
Original file line number Diff line number Diff line change 88 OpenAPISchemaPluginProtocol ,
99 PluginProtocol ,
1010 PluginRegistry ,
11+ ReceiveRoutePlugin ,
1112 SerializationPlugin ,
1213 SerializationPluginProtocol ,
1314)
2223 "OpenAPISchemaPluginProtocol" ,
2324 "PluginProtocol" ,
2425 "PluginRegistry" ,
26+ "ReceiveRoutePlugin" ,
2527 "SerializationPlugin" ,
2628 "SerializationPluginProtocol" ,
2729)
Original file line number Diff line number Diff line change 2727 "OpenAPISchemaPluginProtocol" ,
2828 "PluginProtocol" ,
2929 "PluginRegistry" ,
30+ "ReceiveRoutePlugin" ,
3031 "SerializationPlugin" ,
3132 "SerializationPluginProtocol" ,
3233)
You can’t perform that action at this time.
0 commit comments