pub struct Response { /* private fields */ }
Expand description
A wrapper around Hyper Response.
Implementations§
source§impl Response
impl Response
sourcepub fn headers(&self) -> &HeaderMap<HeaderValue>
pub fn headers(&self) -> &HeaderMap<HeaderValue>
Return Response HTTP headers.
sourcepub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>
pub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>
Return Response HTTP headers.
Examples
let mut res = Response::new();
res.headers_mut().insert(
header::CONTENT_TYPE,
HeaderValue::from_static("text/plain")
);
sourcepub fn set_headers(&mut self, headers: HeaderMap<HeaderValue>)
pub fn set_headers(&mut self, headers: HeaderMap<HeaderValue>)
Set Response’s HTTP headers.
sourcepub fn with_headers(self, headers: HeaderMap<HeaderValue>) -> Self
pub fn with_headers(self, headers: HeaderMap<HeaderValue>) -> Self
Builder set Response’s HTTP headers.
sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Return Response HTTP status code.
sourcepub fn status_mut(&mut self) -> &mut StatusCode
pub fn status_mut(&mut self) -> &mut StatusCode
Get mutable reference to Response’s status code.
sourcepub fn set_status(&mut self, status: u16)
pub fn set_status(&mut self, status: u16)
sourcepub fn with_status(self, status: u16) -> Self
pub fn with_status(self, status: u16) -> Self
sourcepub fn redirect(&mut self, url: &'static str)
pub fn redirect(&mut self, url: &'static str)
Set Response’s redirect location as status code.
Examples
let mut res = Response::new();
res.redirect("/example/moved");
sourcepub fn with_redirect(self, url: &'static str) -> Self
pub fn with_redirect(self, url: &'static str) -> Self
Set Response’s redirect location as status code.
Examples
let res = Response::new()
.with_redirect("/example/moved");
sourcepub fn html(&mut self, html: impl Into<String>)
pub fn html(&mut self, html: impl Into<String>)
Wrapper around Response.set_body for the HTML context type.
sourcepub fn with_html(self, html: impl Into<String>) -> Self
pub fn with_html(self, html: impl Into<String>) -> Self
Wrapper around Response.set_body for the HTML context type.
sourcepub fn css(&mut self, css: impl Fn(&mut CssBuilder))
pub fn css(&mut self, css: impl Fn(&mut CssBuilder))
Wrapper around Response.set_body for the CSS context type.
sourcepub fn with_css(self, css: impl Fn(&mut CssBuilder)) -> Self
pub fn with_css(self, css: impl Fn(&mut CssBuilder)) -> Self
Wrapper around Response.set_body for the CSS context type.
sourcepub fn js(&mut self, js: impl Fn(&mut JsBuilder))
pub fn js(&mut self, js: impl Fn(&mut JsBuilder))
Wrapper around Response.set_body for the JS context type.
sourcepub fn with_js(self, js: impl Fn(&mut JsBuilder)) -> Self
pub fn with_js(self, js: impl Fn(&mut JsBuilder)) -> Self
Wrapper around Response.set_body for the JS context type.
sourcepub fn json<T: Serialize + Send + Sync>(
&mut self,
json: impl Fn(&mut JsonBuilder<T>)
)
pub fn json<T: Serialize + Send + Sync>(
&mut self,
json: impl Fn(&mut JsonBuilder<T>)
)
Wrapper around Response.set_body for the JSON context type.
Examples
use direkuta::prelude::*;
#[derive(Serialize)]
struct Example {
hello: String,
}
let mut res = Response::new();
res.json(|j| {
j.body(Example {
hello: String::from("world"),
});
});
sourcepub fn with_json<T: Serialize + Send + Sync>(
self,
json: impl Fn(&mut JsonBuilder<T>)
) -> Self
pub fn with_json<T: Serialize + Send + Sync>(
self,
json: impl Fn(&mut JsonBuilder<T>)
) -> Self
Builder function for Json responses.
Examples
use direkuta::prelude::*;
#[derive(Serialize)]
struct Example {
hello: String,
}
let res = Response::new()
.with_json(|j| {
j.body(Example {
hello: String::from("world"),
});
});
sourcepub fn json_body<T: Serialize + Send + Sync>(&mut self, json: T)
pub fn json_body<T: Serialize + Send + Sync>(&mut self, json: T)
Builder function for Json responses.
Examples
use direkuta::prelude::*;
#[derive(Serialize)]
struct Example {
hello: String,
}
let res = Response::new();
res.json_body(Example {
hello: String::from("world"),
});
sourcepub fn into_hyper(self) -> Response<Body>
pub fn into_hyper(self) -> Response<Body>
Transform the Response into a Hyper Response.