pub trait Responder {
    type Body: MessageBody + 'static;
    fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body>ⓘNotable traits for HttpResponse<BoxBody>impl Future for HttpResponse<BoxBody>    type Output = Result<Response<BoxBody>, Error>;;
    fn customize(self) -> CustomizeResponder<Self>
    where
        Self: Sized,
    { ... }
}Expand description
Trait implemented by types that can be converted to an HTTP response.
Any types that implement this trait can be used in the return type of a handler.
Required Associated Types
type Body: MessageBody + 'static
Required Methods
fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body>ⓘNotable traits for HttpResponse<BoxBody>impl Future for HttpResponse<BoxBody>    type Output = Result<Response<BoxBody>, Error>;
fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body>ⓘNotable traits for HttpResponse<BoxBody>impl Future for HttpResponse<BoxBody>    type Output = Result<Response<BoxBody>, Error>;
Convert self to HttpResponse.
Provided Methods
fn customize(self) -> CustomizeResponder<Self> where
    Self: Sized, 
fn customize(self) -> CustomizeResponder<Self> where
    Self: Sized, 
Wraps responder to allow alteration of its response.
See CustomizeResponder docs for its capabilities.
Examples
use actix_web::{Responder, http::StatusCode, test::TestRequest};
let responder = "Hello world!"
    .customize()
    .with_status(StatusCode::BAD_REQUEST)
    .insert_header(("x-hello", "world"));
let request = TestRequest::default().to_http_request();
let response = responder.respond_to(&request);
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
assert_eq!(response.headers().get("x-hello").unwrap(), "world");Implementations on Foreign Types
sourceimpl Responder for ResponseBuilder
 
impl Responder for ResponseBuilder
type Body = BoxBody
fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body>ⓘNotable traits for HttpResponse<BoxBody>impl Future for HttpResponse<BoxBody>    type Output = Result<Response<BoxBody>, Error>;
sourceimpl<T> Responder for Option<T> where
    T: Responder,
    <T::Body as MessageBody>::Error: Into<Box<dyn Error>>, 
 
impl<T> Responder for Option<T> where
    T: Responder,
    <T::Body as MessageBody>::Error: Into<Box<dyn Error>>, 
type Body = EitherBody<<T as Responder>::Body, BoxBody>
fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body>ⓘNotable traits for HttpResponse<BoxBody>impl Future for HttpResponse<BoxBody>    type Output = Result<Response<BoxBody>, Error>;
sourceimpl<T, E> Responder for Result<T, E> where
    T: Responder,
    <T::Body as MessageBody>::Error: Into<Box<dyn Error>>,
    E: Into<Error>, 
 
impl<T, E> Responder for Result<T, E> where
    T: Responder,
    <T::Body as MessageBody>::Error: Into<Box<dyn Error>>,
    E: Into<Error>, 
type Body = EitherBody<<T as Responder>::Body, BoxBody>
fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body>ⓘNotable traits for HttpResponse<BoxBody>impl Future for HttpResponse<BoxBody>    type Output = Result<Response<BoxBody>, Error>;
sourceimpl<T: Responder> Responder for (T, StatusCode)
 
impl<T: Responder> Responder for (T, StatusCode)
type Body = <T as Responder>::Body
fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body>ⓘNotable traits for HttpResponse<BoxBody>impl Future for HttpResponse<BoxBody>    type Output = Result<Response<BoxBody>, Error>;
sourceimpl Responder for &'static [u8]
 
impl Responder for &'static [u8]
type Body = &'static [u8]
fn respond_to(self, _: &HttpRequest) -> HttpResponse<Self::Body>ⓘNotable traits for HttpResponse<BoxBody>impl Future for HttpResponse<BoxBody>    type Output = Result<Response<BoxBody>, Error>;
sourceimpl Responder for &'static str
 
impl Responder for &'static str
type Body = &'static str
fn respond_to(self, _: &HttpRequest) -> HttpResponse<Self::Body>ⓘNotable traits for HttpResponse<BoxBody>impl Future for HttpResponse<BoxBody>    type Output = Result<Response<BoxBody>, Error>;
sourceimpl Responder for String
 
impl Responder for String
type Body = String
fn respond_to(self, _: &HttpRequest) -> HttpResponse<Self::Body>ⓘNotable traits for HttpResponse<BoxBody>impl Future for HttpResponse<BoxBody>    type Output = Result<Response<BoxBody>, Error>;
sourceimpl Responder for &String
 
impl Responder for &String
type Body = String
fn respond_to(self, _: &HttpRequest) -> HttpResponse<Self::Body>ⓘNotable traits for HttpResponse<BoxBody>impl Future for HttpResponse<BoxBody>    type Output = Result<Response<BoxBody>, Error>;
sourceimpl Responder for Cow<'_, str>
 
impl Responder for Cow<'_, str>
type Body = String
fn respond_to(self, _: &HttpRequest) -> HttpResponse<Self::Body>ⓘNotable traits for HttpResponse<BoxBody>impl Future for HttpResponse<BoxBody>    type Output = Result<Response<BoxBody>, Error>;
Implementors
sourceimpl Responder for HttpResponseBuilder
 
impl Responder for HttpResponseBuilder
sourceimpl Responder for HttpResponse
 
impl Responder for HttpResponse
sourceimpl<L, R> Responder for Either<L, R> where
    L: Responder,
    R: Responder, 
 
impl<L, R> Responder for Either<L, R> where
    L: Responder,
    R: Responder, 
See here for example of usage as a handler return type.
