pub struct HoochAppBuilder { /* private fields */ }Expand description
Builder for configuring and creating a HoochApp instance.
The builder collects middleware and routes, then consumes itself to create a static instance
of the application. Note that middleware and routes are leaked to achieve a 'static lifetime.
Implementations§
Source§impl HoochAppBuilder
impl HoochAppBuilder
Sourcepub fn new(addr: impl ToSocketAddrs) -> Result<Self>
pub fn new(addr: impl ToSocketAddrs) -> Result<Self>
Creates a new HoochAppBuilder from an address that implements ToSocketAddrs.
§Errors
Returns an error if the provided address cannot be resolved.
Sourcepub fn add_middleware<Fut, F>(&mut self, middleware: F)where
Fut: Future<Output = Middleware> + Send + 'static,
F: Fn(HttpRequest<'static>, SocketAddr) -> Fut + Send + Sync + 'static,
pub fn add_middleware<Fut, F>(&mut self, middleware: F)where
Fut: Future<Output = Middleware> + Send + 'static,
F: Fn(HttpRequest<'static>, SocketAddr) -> Fut + Send + Sync + 'static,
Adds a middleware function to the application.
The middleware is a function that receives an HTTP request and the client’s socket address,
and returns a [MiddlewareFuture] indicating whether to continue processing or short-circuit.
Sourcepub fn add_route<FutRoute, FnRoute>(
&mut self,
path: &'static str,
method: HttpMethod,
route: FnRoute,
)where
FnRoute: Fn(HttpRequest<'static>, Params<'static>) -> FutRoute + Sync + Send + 'static,
FutRoute: Future<Output = HttpResponse> + Send + 'static,
pub fn add_route<FutRoute, FnRoute>(
&mut self,
path: &'static str,
method: HttpMethod,
route: FnRoute,
)where
FnRoute: Fn(HttpRequest<'static>, Params<'static>) -> FutRoute + Sync + Send + 'static,
FutRoute: Future<Output = HttpResponse> + Send + 'static,
Adds a new route to the application.
The route is specified by a URI pattern, an HTTP method, and a handler function.
The handler receives the request and extracted route parameters, and returns a [RouterFuture].