Trait actix_web::Responder [−][src]
pub trait Responder {
fn respond_to(self, req: &HttpRequest) -> HttpResponseⓘNotable traits for HttpResponse<Body>impl Future for HttpResponse<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,
{ ... }
}
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 methods
fn respond_to(self, req: &HttpRequest) -> HttpResponseⓘNotable traits for HttpResponse<Body>impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
fn respond_to(self, req: &HttpRequest) -> HttpResponseⓘNotable traits for HttpResponse<Body>impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
Notable traits for HttpResponse<Body>
impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
Convert self to HttpResponse
.
Provided methods
fn with_status(self, status: StatusCode) -> CustomResponder<Self> where
Self: Sized,
fn with_status(self, status: StatusCode) -> CustomResponder<Self> where
Self: Sized,
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,
fn with_header<H>(self, header: H) -> CustomResponder<Self> where
Self: Sized,
H: IntoHeaderPair,
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"))
}
Implementations on Foreign Types
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘNotable traits for HttpResponse<Body>impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
Notable traits for HttpResponse<Body>
impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
fn respond_to(self, req: &HttpRequest) -> HttpResponseⓘNotable traits for HttpResponse<Body>impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
Notable traits for HttpResponse<Body>
impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
fn respond_to(self, req: &HttpRequest) -> HttpResponseⓘNotable traits for HttpResponse<Body>impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
Notable traits for HttpResponse<Body>
impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
fn respond_to(self, req: &HttpRequest) -> HttpResponseⓘNotable traits for HttpResponse<Body>impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
Notable traits for HttpResponse<Body>
impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘNotable traits for HttpResponse<Body>impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
Notable traits for HttpResponse<Body>
impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘNotable traits for HttpResponse<Body>impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
Notable traits for HttpResponse<Body>
impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘNotable traits for HttpResponse<Body>impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
Notable traits for HttpResponse<Body>
impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘNotable traits for HttpResponse<Body>impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
Notable traits for HttpResponse<Body>
impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘNotable traits for HttpResponse<Body>impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;
Notable traits for HttpResponse<Body>
impl Future for HttpResponse<Body> type Output = Result<Response<Body>, Error>;