[][src]Trait actix_web::Responder

pub trait Responder {
    type Error: Into<Error>;
    type Future: Future<Output = Result<Response, Self::Error>>;
    fn respond_to(self, req: &HttpRequest) -> Self::Future;

    fn with_status(self, status: StatusCode) -> CustomResponder<Self>
    where
        Self: Sized
, { ... }
fn with_header<K, V>(self, key: K, value: V) -> CustomResponder<Self>
    where
        Self: Sized,
        HeaderName: TryFrom<K>,
        <HeaderName as TryFrom<K>>::Error: Into<HttpError>,
        V: IntoHeaderValue
, { ... } }

Trait implemented by types that can be converted to a http response.

Types that implement this trait can be used as the return type of a handler.

Associated Types

type Error: Into<Error>

The associated error which can be returned.

type Future: Future<Output = Result<Response, Self::Error>>

The future response value.

Loading content...

Required methods

fn respond_to(self, req: &HttpRequest) -> Self::Future

Convert itself to AsyncResult or Error.

Loading content...

Provided methods

fn with_status(self, status: StatusCode) -> CustomResponder<Self> where
    Self: Sized

Override a status code for a Responder.

use actix_web::{HttpRequest, Responder, http::StatusCode};

fn index(req: HttpRequest) -> impl Responder {
    "Welcome!".with_status(StatusCode::OK)
}

fn with_header<K, V>(self, key: K, value: V) -> CustomResponder<Self> where
    Self: Sized,
    HeaderName: TryFrom<K>,
    <HeaderName as TryFrom<K>>::Error: Into<HttpError>,
    V: IntoHeaderValue

Add header to the Responder's response.

use actix_web::{web, HttpRequest, Responder};
use serde::Serialize;

#[derive(Serialize)]
struct MyObj {
    name: String,
}

fn index(req: HttpRequest) -> impl Responder {
    web::Json(
        MyObj{name: "Name".to_string()}
    )
    .with_header("x-version", "1.2.3")
}
Loading content...

Implementations on Foreign Types

impl<T> Responder for Option<T> where
    T: Responder
[src]

type Error = T::Error

type Future = EitherFuture<T::Future, Ready<Result<Response, T::Error>>>

impl<T, E> Responder for Result<T, E> where
    T: Responder,
    E: Into<Error>, 
[src]

type Error = Error

type Future = EitherFuture<ResponseFuture<T::Future, T::Error>, Ready<Result<Response, Error>>>

impl<T> Responder for (T, StatusCode) where
    T: Responder
[src]

type Error = T::Error

type Future = CustomResponderFut<T>

impl Responder for &'static str[src]

impl Responder for &'static [u8][src]

impl Responder for String[src]

impl<'a> Responder for &'a String[src]

Loading content...

Implementors

impl Responder for ResponseBuilder[src]

impl Responder for Bytes[src]

impl Responder for BytesMut[src]

impl Responder for Response[src]

impl<A, B> Responder for Either<A, B> where
    A: Responder,
    B: Responder
[src]

type Error = Error

type Future = EitherResponder<A, B>

impl<T> Responder for InternalError<T> where
    T: Debug + Display + 'static, 
[src]

impl<T: Serialize> Responder for Form<T>[src]

impl<T: Serialize> Responder for Json<T>[src]

Loading content...