pub trait HttpService:
Send
+ Sync
+ 'static {
// Required method
fn request(
&self,
route: &str,
req: &HttpRequest,
body: &mut dyn HttpRead,
) -> impl Future<Output = HttpResult> + Send;
// Provided method
fn filter(&self, route: &str, req: &HttpRequest) -> HttpResult<()> { ... }
}Expand description
Basic building block of your web application
Use it to implement the service, and use HttpServiceRaw to call it from a &dyn reference
Required Methods§
Sourcefn request(
&self,
route: &str,
req: &HttpRequest,
body: &mut dyn HttpRead,
) -> impl Future<Output = HttpResult> + Send
fn request( &self, route: &str, req: &HttpRequest, body: &mut dyn HttpRead, ) -> impl Future<Output = HttpResult> + Send
Serve the request
Equivalent signature:
async fn request(&self, route: &str, req: &HttpRequest, body: &dyn HttpRead) -> HttpResult
The route argument contains the resolved route, while req.route contains the full original route.
Always use route instead of req.route!
Provided Methods§
Sourcefn filter(&self, route: &str, req: &HttpRequest) -> HttpResult<()>
fn filter(&self, route: &str, req: &HttpRequest) -> HttpResult<()>
Checks if request is valid
By default, it checks that route is "/", method is HttpMethod::Get and req.len is 0
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.