Trait actix_web::Responder[][src]

pub trait Responder {
    fn respond_to(self, req: &HttpRequest) -> HttpResponse

Notable traits for Response<Body>

impl Future for Response<Body> type Output = Result<Response<Body>, Error>;
; fn with_status(self, status: StatusCode) -> CustomResponder<Self>
    where
        Self: Sized
, { ... }
fn with_header<H>(self, header: H) -> CustomResponder<Self>
    where
        Self: Sized,
        H: IntoHeaderPair
, { ... } }

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 methods

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

Notable traits for Response<Body>

impl Future for Response<Body> type Output = Result<Response<Body>, Error>;
[src]

Convert self to HttpResponse.

Loading content...

Provided methods

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

Override a status code for a Responder.

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

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

fn with_header<H>(self, header: H) -> CustomResponder<Self> where
    Self: Sized,
    H: IntoHeaderPair
[src]

Insert header to the final response.

Overrides other headers with the same name.

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_owned() })
        .with_header(("x-version", "1.2.3"))
}
Loading content...

Implementations on Foreign Types

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

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

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

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 HttpResponse[src]

impl Responder for Bytes[src]

impl Responder for BytesMut[src]

impl<L, R> Responder for Either<L, R> where
    L: Responder,
    R: Responder
[src]

See here for example of usage as a handler return type.

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

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

See here for example of usage as a handler return type.

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

Creates response with OK status code, correct content type header, and serialized JSON payload.

If serialization failed

Loading content...