Trait actix_web::Responder [−][src]
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ⓘ
[src]
Convert self to HttpResponse
.
Provided methods
fn with_status(self, status: StatusCode) -> CustomResponder<Self> where
Self: Sized,
[src]
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,
[src]
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
impl<T: Responder> Responder for Option<T>
[src]
fn respond_to(self, req: &HttpRequest) -> HttpResponseⓘ
[src]
impl<T, E> Responder for Result<T, E> where
T: Responder,
E: Into<Error>,
[src]
T: Responder,
E: Into<Error>,
fn respond_to(self, req: &HttpRequest) -> HttpResponseⓘ
[src]
impl<T: Responder> Responder for (T, StatusCode)
[src]
fn respond_to(self, req: &HttpRequest) -> HttpResponseⓘ
[src]
impl Responder for &'static str
[src]
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘ
[src]
impl Responder for &'static [u8]
[src]
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘ
[src]
impl Responder for String
[src]
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘ
[src]
impl<'a> Responder for &'a String
[src]
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘ
[src]
Implementors
impl Responder for ResponseBuilder
[src]
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘ
[src]
impl Responder for HttpResponse
[src]
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘ
[src]
impl Responder for Bytes
[src]
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘ
[src]
impl Responder for BytesMut
[src]
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘ
[src]
impl<L, R> Responder for Either<L, R> where
L: Responder,
R: Responder,
[src]
L: Responder,
R: Responder,
See here for example of usage as a handler return type.
fn respond_to(self, req: &HttpRequest) -> HttpResponseⓘ
[src]
impl<T> Responder for InternalError<T> where
T: Debug + Display + 'static,
[src]
T: Debug + Display + 'static,
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘ
[src]
impl<T: Serialize> Responder for Form<T>
[src]
See here for example of usage as a handler return type.
fn respond_to(self, _: &HttpRequest) -> HttpResponseⓘ
[src]
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