route_table.py
Provides routing table class.
RouteTable
Stores and manages registered routes.
Provides lookup for handlers based on URL and HTTP method.
Source code in jetweb/routing/route_table.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
add_route(prefix, endpoint, handler, methods=None)
Register a new route.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Endpoint prefix. |
required |
endpoint
|
str
|
Route endpoint. |
required |
handler
|
Callable
|
Request handler. |
required |
methods
|
Union[Iterable[str], None]
|
Allowed request methods (default: ["GET"]). Adds "OPTIONS" if GET is allowed. |
None
|
Source code in jetweb/routing/route_table.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
find_handler(endpoint, method)
Find a request handler for the given endpoint and method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
Request endpoint. |
required |
method
|
str
|
Request method. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Callable, dict]
|
Request handler and parsed path parameters. |
Raises:
| Type | Description |
|---|---|
HTTPException(404)
|
If no route matches for endpoint. |
HTTPException(405)
|
If no method matches for matched route. |
Source code in jetweb/routing/route_table.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
include(prefix, route_table)
Include routes from another table under a prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Endpoint prefix. |
required |
route_table
|
RouteTable
|
Route table with routes for including. |
required |
Source code in jetweb/routing/route_table.py
23 24 25 26 27 28 29 30 31 32 33 | |