HTTP servers (Effect's HttpServer): the HttpServer service a
backend provides (live_server.layer), serving an app as a
layer, and the test client.
::
app = router.to_http_effect(...)
main = server.serve(app).pipe(layer.provide(live_server.layer(port=8080)))Values#
| Attribute | Type | Description |
|---|---|---|
log_address | Effect[None, Never, HttpServer] | |
make_test_client | Effect[HttpClientService[Any], Never, HttpServer | HttpClient] | The |
layer_test_client | Layer[HttpClient, Never, HttpServer | HttpClient] | An |
layer_services | Layer[Path | HttpPlatform | FileSystem | Generator] | What servers need: |
Types#
| Type | Definition | Description |
|---|---|---|
HttpApp | type HttpApp = Effect[HttpServerResponse, Any, Any] | |
Middleware | type Middleware = Callable[[HttpApp], HttpApp] |
Classes#
Functions#
make#
make(*, serve, address) -> HttpServerService| Parameter | Type | Description |
|---|---|---|
serve | Callable[[HttpApp, Middleware | None], Effect[None, Never, Scope]] | |
address | SocketAddress |
Returns HttpServerService
def make(
*,
serve: Callable[[HttpApp, Middleware | None], Effect[None, Never, Scope]],
address: SocketAddress,
) -> HttpServerService:
return HttpServerService(serve, address)serve_effect#
serve_effect[E](app: _AppIn[E, Never], /) -> Effect[None, Never, Scope | HttpServer]
serve_effect[E, R](app: _AppIn[E, R], /) -> Effect[None, Never, Scope | HttpServer | R]
serve_effect[E, EM](app: _AppIn[E, Never], middleware: Callable[[_AppIn[E, Never]], _AppIn[EM, Never]], /) -> Effect[None, Never, Scope | HttpServer]
serve_effect[E, EM, RM](app: _AppIn[E, Never], middleware: Callable[[_AppIn[E, Never]], _AppIn[EM, RM]], /) -> Effect[None, Never, Scope | HttpServer | RM]
serve_effect[E, R, EM, RM](app: _AppIn[E, R], middleware: Callable[[_AppIn[E, R]], _AppIn[EM, RM]], /) -> Effect[None, Never, Scope | HttpServer | RM]Serve app (through middleware) until the scope closes.
| Parameter | Type | Description |
|---|---|---|
app | ||
middleware | = None |
@overload
def serve_effect[E](app: _AppIn[E, Never], /) -> Effect[None, Never, Scope | HttpServer]: ...
@overload
def serve_effect[E, R](app: _AppIn[E, R], /) -> Effect[None, Never, Scope | HttpServer | R]: ...
@overload
def serve_effect[E, EM](
app: _AppIn[E, Never], middleware: Callable[[_AppIn[E, Never]], _AppIn[EM, Never]], /
) -> Effect[None, Never, Scope | HttpServer]: ...
@overload
def serve_effect[E, EM, RM](
app: _AppIn[E, Never], middleware: Callable[[_AppIn[E, Never]], _AppIn[EM, RM]], /
) -> Effect[None, Never, Scope | HttpServer | RM]: ...
@overload
def serve_effect[E, R, EM, RM](
app: _AppIn[E, R], middleware: Callable[[_AppIn[E, R]], _AppIn[EM, RM]], /
) -> Effect[None, Never, Scope | HttpServer | RM]: ...
def serve_effect(
app: Effect[HttpServerResponse, Any, Any], middleware: Middleware | None = None, /
) -> Effect[None, Never, Any]:
"""Serve ``app`` (through ``middleware``) until the scope closes."""
require_effect(app, "app")
return HttpServer().flat_map(lambda server: server.serve(app, middleware))serve#
serve[E](app: _AppIn[E, Never], /) -> Layer[Never, Never, HttpServer]
serve[E, R](app: _AppIn[E, R], /) -> Layer[Never, Never, HttpServer | R]
serve[E, EM](app: _AppIn[E, Never], middleware: Callable[[_AppIn[E, Never]], _AppIn[EM, Never]], /) -> Layer[Never, Never, HttpServer]
serve[E, EM, RM](app: _AppIn[E, Never], middleware: Callable[[_AppIn[E, Never]], _AppIn[EM, RM]], /) -> Layer[Never, Never, HttpServer | RM]
serve[E, R, EM, RM](app: _AppIn[E, R], middleware: Callable[[_AppIn[E, R]], _AppIn[EM, RM]], /) -> Layer[Never, Never, HttpServer | RM]A layer serving app (through middleware) while it is in
use.
| Parameter | Type | Description |
|---|---|---|
app | ||
middleware | = None |
@overload
def serve[E](app: _AppIn[E, Never], /) -> Layer[Never, Never, HttpServer]: ...
@overload
def serve[E, R](app: _AppIn[E, R], /) -> Layer[Never, Never, HttpServer | R]: ...
@overload
def serve[E, EM](
app: _AppIn[E, Never], middleware: Callable[[_AppIn[E, Never]], _AppIn[EM, Never]], /
) -> Layer[Never, Never, HttpServer]: ...
@overload
def serve[E, EM, RM](
app: _AppIn[E, Never], middleware: Callable[[_AppIn[E, Never]], _AppIn[EM, RM]], /
) -> Layer[Never, Never, HttpServer | RM]: ...
@overload
def serve[E, R, EM, RM](
app: _AppIn[E, R], middleware: Callable[[_AppIn[E, R]], _AppIn[EM, RM]], /
) -> Layer[Never, Never, HttpServer | RM]: ...
def serve(
app: Effect[HttpServerResponse, Any, Any], middleware: Middleware | None = None, /
) -> Layer[Never, Never, Any]:
"""A layer serving ``app`` (through ``middleware``) while it is in
use."""
require_effect(app, "app")
return effect_discard(serve_effect(app, middleware) if middleware else serve_effect(app))format_address#
format_address(address) -> strhttp://host:port, or unix://path.
| Parameter | Type | Description |
|---|---|---|
address | SocketAddress |
Returns str
def format_address(address: SocketAddress) -> str:
"""``http://host:port``, or ``unix://path``."""
return format_url_unsafe(address)address_formatted_with#
address_formatted_with[A, E, R](f) -> Effect[A, E, HttpServer | R]| Parameter | Type | Description |
|---|---|---|
f | Callable[[str], Effect[A, E, R]] |
Returns Effect[A, E, HttpServer | R]
def address_formatted_with[A, E, R](
f: Callable[[str], Effect[A, E, R]],
) -> Effect[A, E, HttpServer | R]:
return HttpServer().flat_map(lambda server: f(format_address(server.address)))with_log_address#
with_log_address[A, E, R](layer) -> Layer[A, E, R | HttpServer]layer, logging the server's address once built.
| Parameter | Type | Description |
|---|---|---|
layer | Layer[A, E, R] |
Returns Layer[A, E, R | HttpServer]
def with_log_address[A, E, R](layer: Layer[A, E, R]) -> Layer[A, E, R | HttpServer]:
"""``layer``, logging the server's address once built."""
return effect_discard(log_address).pipe(provide_merge(layer))