Add routes while layers build; as_http_effect serves them.
Functions#
__init__#
__init__(_core, _prefix=None) -> None| Parameter | Type | Description |
|---|---|---|
_core | _Core | |
_prefix | str | None = None |
prefixed#
prefixed(prefix) -> HttpRouterServiceThis router with every route mounted under prefix.
| Parameter | Type | Description |
|---|---|---|
prefix | str |
Returns HttpRouterService
def prefixed(self, prefix: str) -> HttpRouterService:
"""This router with every route mounted under ``prefix``."""
prefix = remove_trailing_slash(prefix)
return HttpRouterService(
self._core, prefix if self._prefix is None else prefix_path(prefix, self._prefix)
)add#
add(method: Method, path: str, handler: HttpServerResponse | Effect[HttpServerResponse, Never, Provided] | Callable[[ServerRequest], Effect[HttpServerResponse, Never, Provided]], *, uninterruptible: bool = False) -> Effect[None]
add[E](method: Method, path: str, handler: Effect[HttpServerResponse, E, Provided] | Callable[[ServerRequest], Effect[HttpServerResponse, E, Provided]], *, uninterruptible: bool = False) -> Effect[None, Never, Raises[E]]
add[R](method: Method, path: str, handler: Effect[HttpServerResponse, Never, R | Provided] | Callable[[ServerRequest], Effect[HttpServerResponse, Never, R | Provided]], *, uninterruptible: bool = False) -> Effect[None, Never, Requires[R]]
add[E, R](method: Method, path: str, handler: Effect[HttpServerResponse, E, R | Provided] | Callable[[ServerRequest], Effect[HttpServerResponse, E, R | Provided]], *, uninterruptible: bool = False) -> Effect[None, Never, Requires[R] | Raises[E]]Add a route. handler is a response, an effect, or a function
of the request; it runs interruptibly unless uninterruptible.
| Parameter | Type | Description |
|---|---|---|
method | ||
path | ||
handler | ||
uninterruptible | = False |
@overload
def add(
self,
method: Method,
path: str,
handler: HttpServerResponse
| Effect[HttpServerResponse, Never, Provided]
| Callable[[ServerRequest], Effect[HttpServerResponse, Never, Provided]],
*,
uninterruptible: bool = False,
) -> Effect[None]: ...
@overload
def add[E](
self,
method: Method,
path: str,
handler: Effect[HttpServerResponse, E, Provided]
| Callable[[ServerRequest], Effect[HttpServerResponse, E, Provided]],
*,
uninterruptible: bool = False,
) -> Effect[None, Never, Raises[E]]: ...
@overload
def add[R](
self,
method: Method,
path: str,
handler: Effect[HttpServerResponse, Never, R | Provided]
| Callable[[ServerRequest], Effect[HttpServerResponse, Never, R | Provided]],
*,
uninterruptible: bool = False,
) -> Effect[None, Never, Requires[R]]: ...
@overload
def add[E, R](
self,
method: Method,
path: str,
handler: Effect[HttpServerResponse, E, R | Provided]
| Callable[[ServerRequest], Effect[HttpServerResponse, E, R | Provided]],
*,
uninterruptible: bool = False,
) -> Effect[None, Never, Requires[R] | Raises[E]]: ...
def add(
self,
method: Method,
path: str,
# Spelled out (not ``Handler``): a function is a valid handler.
handler: HttpServerResponse
| Effect[HttpServerResponse, Any, Any]
| Callable[[ServerRequest], Effect[HttpServerResponse, Any, Any]],
*,
uninterruptible: bool = False,
) -> Effect[None, Never, Any]:
"""Add a route. ``handler`` is a response, an effect, or a function
of the request; it runs interruptibly unless ``uninterruptible``."""
if self._prefix is None:
return self._core.add_all([Route(method, path, to_effect(handler), uninterruptible)])
route = Route(
method,
prefix_path(path, self._prefix),
to_effect(handler),
uninterruptible,
self._prefix,
)
return self._core.add_all([route])add_all#
add_all(routes: Sequence[Route[Never, Never]], /) -> Effect[None]
add_all[E](routes: Sequence[Route[E, Never]], /) -> Effect[None, Never, Raises[E]]
add_all[R](routes: Sequence[Route[Never, R]], /) -> Effect[None, Never, Requires[R]]
add_all[E, R](routes: Sequence[Route[E, R]], /) -> Effect[None, Never, Requires[R] | Raises[E]]Add several routes (under this router's prefix).
| Parameter | Type | Description |
|---|---|---|
routes |
@overload
def add_all(self, routes: Sequence[Route[Never, Never]], /) -> Effect[None]: ...
@overload
def add_all[E](
self, routes: Sequence[Route[E, Never]], /
) -> Effect[None, Never, Raises[E]]: ...
@overload
def add_all[R](
self, routes: Sequence[Route[Never, R]], /
) -> Effect[None, Never, Requires[R]]: ...
@overload
def add_all[E, R](
self, routes: Sequence[Route[E, R]], /
) -> Effect[None, Never, Requires[R] | Raises[E]]: ...
def add_all(self, routes: Sequence[Route[Any, Any]], /) -> Effect[None, Never, Any]:
"""Add several routes (under this router's prefix)."""
if self._prefix is not None:
routes = [prefix_route(self._prefix)(route) for route in routes]
return self._core.add_all(routes)add_global_middleware#
add_global_middleware(middleware) -> Effect[None]Wrap every request, matched or not. Added first is outermost.
| Parameter | Type | Description |
|---|---|---|
middleware | GlobalMiddlewareFn |
Returns Effect[None]
def add_global_middleware(self, middleware: GlobalMiddlewareFn) -> Effect[None]:
"""Wrap every request, matched or not. Added first is outermost."""
return sync(lambda: self._add_global(middleware))as_http_effect#
as_http_effect() -> Effect[HttpServerResponse, Any, HttpServerRequest]The app: routes each request, failing with RouteNotFound
when nothing matches.
Returns Effect[HttpServerResponse, Any, HttpServerRequest]
def as_http_effect(self) -> Effect[HttpServerResponse, Any, HttpServerRequest]:
"""The app: routes each request, failing with ``RouteNotFound``
when nothing matches."""
return self._core.as_http_effect()