Trait HttpService

Source
pub trait HttpService {
    type Error;
    type ResBody: Body;

    // Required method
    fn call(
        &mut self,
        req: IncomingRequest,
    ) -> impl Future<Output = Result<Response<Self::ResBody>, Self::Error>> + Send;
}
Expand description

A trait representing an HTTP service.

This trait must be used in combination with HttpServiceFactory. It is very similar to tower’s service trait and implemented for all types that implement tower::Service<IncomingRequest>.

Required Associated Types§

Source

type Error

The error type that can be returned by call.

Source

type ResBody: Body

The response body type that is returned by call.

Required Methods§

Source

fn call( &mut self, req: IncomingRequest, ) -> impl Future<Output = Result<Response<Self::ResBody>, Self::Error>> + Send

Handle an incoming request.

This method is called for each incoming request. The service must return a response for the given request.

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.

Implementors§

Source§

impl<F, Fut, E, B> HttpService for FnHttpService<F>
where F: Fn(IncomingRequest) -> Fut, Fut: Future<Output = Result<Response<B>, E>> + Send, E: Error, B: Body,

Source§

impl<T, B> HttpService for T
where T: Service<IncomingRequest, Response = Response<B>> + Send, T::Future: Send, B: Body,

Available on crate feature tower only.
Source§

type Error = <T as Service<Request<IncomingBody>>>::Error

Source§

type ResBody = B