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