Skip to content

Commit 802d7fd

Browse files
committed
Added Server.add_routes for importing external routes
1 parent e6a0b02 commit 802d7fd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

adafruit_httpserver/server.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,29 @@ def route_decorator(func: Callable) -> Callable:
123123

124124
return route_decorator
125125

126+
def add_routes(self, routes: List[Route]) -> None:
127+
"""
128+
Add multiple routes at once.
129+
130+
:param List[Route] routes: List of routes to add to the server
131+
132+
Example::
133+
134+
from separate_file import external_route1, external_route2
135+
136+
...
137+
138+
server.add_routes([
139+
Route("/example", GET, route_func1, append_slash=True),
140+
Route("/example/<my_parameter>", GET, route_func2),
141+
Route("/example/..../something", [GET, POST], route_func3),
142+
external_route1,
143+
external_route2,
144+
]}
145+
"""
146+
for route in routes:
147+
self._routes.add(route)
148+
126149
def _verify_can_start(self, host: str, port: int) -> None:
127150
"""Check if the server can be successfully started. Raises RuntimeError if not."""
128151

0 commit comments

Comments
 (0)