[−][src]Trait ntex::web::Responder
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
[src]
The associated error which can be returned.
type Future: Future<Output = Response>
[src]
The future response value.
Required methods
pub fn respond_to(self, req: &HttpRequest) -> Self::Future
[src]
Convert itself to AsyncResult
or Error
.
Provided methods
pub fn with_status(self, status: StatusCode) -> CustomResponder<Self, Err> where
Self: Sized,
[src]
Self: Sized,
Override a status code for a Responder.
use ntex::http::StatusCode; use ntex::web::{HttpRequest, Responder}; fn index(req: HttpRequest) -> impl Responder { "Welcome!".with_status(StatusCode::OK) }
pub fn with_header<K, V>(self, key: K, value: V) -> CustomResponder<Self, Err> where
Self: Sized,
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
[src]
Self: Sized,
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
Add header to the Responder's response.
use ntex::web::{self, HttpRequest, Responder}; use serde::Serialize; #[derive(Serialize)] struct MyObj { name: String, } async fn index(req: HttpRequest) -> impl Responder { web::types::Json( MyObj { name: "Name".to_string() } ) .with_header("x-version", "1.2.3") }
Implementations on Foreign Types
impl<T, Err> Responder<Err> for Option<T> where
T: Responder<Err>,
Err: ErrorRenderer,
[src]
T: Responder<Err>,
Err: ErrorRenderer,
type Error = T::Error
type Future = EitherFuture<T::Future, Ready<Response>>
pub fn respond_to(self, req: &HttpRequest) -> Self::Future
[src]
impl<T, E, Err> Responder<Err> for Result<T, E> where
T: Responder<Err>,
E: Into<Err::Container>,
Err: ErrorRenderer,
[src]
T: Responder<Err>,
E: Into<Err::Container>,
Err: ErrorRenderer,
type Error = T::Error
type Future = EitherFuture<T::Future, Ready<Response>>
pub fn respond_to(self, req: &HttpRequest) -> Self::Future
[src]
impl<T, Err> Responder<Err> for (T, StatusCode) where
T: Responder<Err>,
Err: ErrorRenderer,
[src]
T: Responder<Err>,
Err: ErrorRenderer,
type Error = T::Error
type Future = CustomResponderFut<T, Err>
pub fn respond_to(self, req: &HttpRequest) -> Self::Future
[src]
impl<Err: ErrorRenderer> Responder<Err> for &'static str
[src]
type Error = Err::Container
type Future = Ready<Response>
pub fn respond_to(self, _: &HttpRequest) -> Self::Future
[src]
impl<Err: ErrorRenderer> Responder<Err> for &'static [u8]
[src]
type Error = Err::Container
type Future = Ready<Response>
pub fn respond_to(self, _: &HttpRequest) -> Self::Future
[src]
impl<Err: ErrorRenderer> Responder<Err> for String
[src]
type Error = Err::Container
type Future = Ready<Response>
pub fn respond_to(self, _: &HttpRequest) -> Self::Future
[src]
impl<'a, Err: ErrorRenderer> Responder<Err> for &'a String
[src]
type Error = Err::Container
type Future = Ready<Response>
pub fn respond_to(self, _: &HttpRequest) -> Self::Future
[src]
impl<Err: ErrorRenderer> Responder<Err> for Bytes
[src]
type Error = Err::Container
type Future = Ready<Response>
pub fn respond_to(self, _: &HttpRequest) -> Self::Future
[src]
impl<Err: ErrorRenderer> Responder<Err> for BytesMut
[src]
type Error = Err::Container
type Future = Ready<Response>
pub fn respond_to(self, _: &HttpRequest) -> Self::Future
[src]
Implementors
impl<A, B, Err> Responder<Err> for Either<A, B> where
A: Responder<Err>,
B: Responder<Err>,
Err: ErrorRenderer,
[src]
A: Responder<Err>,
B: Responder<Err>,
Err: ErrorRenderer,
Combines two different responder types into a single type
use ntex::web::{Either, HttpResponse}; fn index() -> Either<HttpResponse, &'static str> { if is_a_variant() { // <- choose left variant Either::Left(HttpResponse::BadRequest().body("Bad data")) } else { // <- Right variant Either::Right("Hello!") } }
type Error = Err::Container
type Future = EitherFuture<A::Future, B::Future>
pub fn respond_to(self, req: &HttpRequest) -> Self::Future
[src]
impl<Err: ErrorRenderer> Responder<Err> for Response
[src]
type Error = Err::Container
type Future = Ready<Response>
pub fn respond_to(self, _: &HttpRequest) -> Self::Future
[src]
impl<Err: ErrorRenderer> Responder<Err> for ResponseBuilder
[src]
type Error = Err::Container
type Future = Ready<Response>
pub fn respond_to(mut self: Self, _: &HttpRequest) -> Self::Future
[src]
impl<T, Err> Responder<Err> for InternalError<T, Err> where
T: Debug + Display + 'static,
Err: ErrorRenderer,
[src]
T: Debug + Display + 'static,
Err: ErrorRenderer,
type Error = Err::Container
type Future = Ready<Response>
pub fn respond_to(self, req: &HttpRequest) -> Self::Future
[src]
impl<T: Serialize, Err: ErrorRenderer> Responder<Err> for Form<T> where
Err::Container: From<Error>,
[src]
Err::Container: From<Error>,
type Error = Error
type Future = Ready<Response>
pub fn respond_to(self, req: &HttpRequest) -> Self::Future
[src]
impl<T: Serialize, Err: ErrorRenderer> Responder<Err> for Json<T> where
Err::Container: From<JsonError>,
[src]
Err::Container: From<JsonError>,