Skip to main content

Crate alux_http_salvo

Crate alux_http_salvo 

Source
Expand description

§alux-http-salvo

alux-http-salvo interprets an alux-http program as executable Salvo routes.

use alux_http::HttpProgramExt;
use alux_http_salvo::SalvoHandlerImpl;

let api = SalvoHandlerImpl::new(App::new());
let router = api.compile_http(api.status_api::<App>()).into_salvo();

salvo::Server::new(salvo::conn::TcpListener::new("0.0.0.0:3000").bind().await).serve(router).await;

A Salvo handler writes into the response it receives rather than returning one, so every output kind here produces a salvo::Response for the endpoint to install. Salvo represents path captures as a map, even when the path has only one parameter. This interpreter extracts that single value directly, so it agrees with the path semantics of the other routers.

§Closing

Salvo owns its accept loop but accepts through a TcpAcceptor, so this crate binds the listener and hands it over. Closing therefore goes through ServerHandle::stop_graceful, which stops accepting and then waits for connections already accepted to close.

That wait takes a timeout, and it matters: Salvo drops the acceptor only once the wait is over, so stop_graceful(None) lets one client holding a connection open hold the address with it. This crate passes 5 seconds, which is what keeps close bounded and its address released. Interprets typed HTTP programs as executable Salvo routes.

The interpretation chooses Salvo’s readers for input roles, its response for output kinds, and Arc for the runtime handle of a semantic context. A Salvo handler writes into the response it is given, so every output kind here answers with one.

Structs§

SalvoBodyInput
Marks a JSON value read from the request body.
SalvoBytesOutput
Renders a semantic result as a raw-byte response.
SalvoCookieInput
Marks a value read from the cookies a caller sent.
SalvoEmptyOutput
Renders a handler that returns nothing as a response with no body.
SalvoEndpoint
Erases what one endpoint does with a request Salvo routed to it.
SalvoFileOutput
Renders a semantic file result as a downloadable response.
SalvoFormInput
Marks a form-encoded value read from the request body.
SalvoHandlerImpl
Interprets typed HTTP programs as executable Salvo routes.
SalvoHeadInput
Marks a value read from the request head.
SalvoHeaderInput
Marks a value read from the headers a caller sent.
SalvoHeaderOutput
Answers with a header the handler stated, beside the body it stated.
SalvoHtmlOutput
Renders a semantic result as an HTML response.
SalvoJsonOutput
Renders a semantic result as a JSON response.
SalvoMultipartInput
Marks an argument read from a body arriving as parts.
SalvoOpen
Carries an open Salvo server that is accepting requests.
SalvoPathInput
Marks a value read from the segments a path bound.
SalvoQueryInput
Marks a value read from the query string.
SalvoRawBodyInput
Marks the request body taken as it arrived.
SalvoRedirectOutput
Renders a semantic location as a redirect.
SalvoResultOutput
Answers with what a failure means when the handler failed, and with the body it states otherwise.
SalvoRoute
Carries a composable collection of Salvo endpoints.
SalvoRouteImpl
Interprets categorical route composition as native Salvo routing.
SalvoSelector
Carries route-selection meaning before it is interpreted by Salvo.
SalvoServer
Serves a Salvo route at the address its setup names.
SalvoStatusOutput
Answers with the status an endpoint declared, around the body it already states.
SalvoStreamOutput
Answers with a body produced over time.
SalvoTextOutput
Renders a semantic result as a plain-text response.

Traits§

FromHeadersAlg
Reads the handler argument the request head states.
FromPayloadAlg
Reads the handler argument a request body states, taken as it arrived.

Functions§

salvo_status
Interprets a portable status as the one Salvo answers with.