pub struct Response {
pub cors: String,
/* private fields */
}Expand description
Response struct to client
Fields§
§cors: StringCross Origin Site
Implementations§
Source§impl Response
impl Response
Sourcepub fn view(template: Template) -> Response
pub fn view(template: Template) -> Response
Send a html file from resources/views directory
§Arguments
- Template - Enum contain the name of file in resources/views
§Examples
use pillow::{
http::*,
templates::{Context, Template}
};
#[controller(method = "GET", path = "/")]
fn index() -> Response {
let mut ctx = Context::new();
Response::view(Template::Tera("index", "tera.html", ctx))
}Sourcepub fn hbs(page: &'static str, data: Value) -> Response
pub fn hbs(page: &'static str, data: Value) -> Response
Send a hbs file from resources/views directory
§Arguments
- page - A String that the page on views directory
- data - Json value
§Examples
use pillow::json;
use pillow::http::*;
#[controller(method = "GET", path = "/")]
fn index() -> Response {
let json = json! ({
"name": "foo"
});
Response::hbs("index", json)
}Sourcepub fn json_from_str(json: &str) -> Response
pub fn json_from_str(json: &str) -> Response
Sourcepub fn text(txt: &str) -> Response
pub fn text(txt: &str) -> Response
Send text to client
§Examples
use pillow::http::*;
#[controller(method = "GET", path = "/")]
fn index() -> Response {
Response::text("hello world")
}Sourcepub fn javascript(&mut self, js: String) -> String
pub fn javascript(&mut self, js: String) -> String
Send javascript to client
pub fn file(content_type: ContentType, content: Vec<u8>) -> Response
Source§impl Response
impl Response
Sourcepub fn insert_string_content(&mut self, content: String)
pub fn insert_string_content(&mut self, content: String)
Insert content in the Response.body
pub fn insert_bytes_content(&mut self, content: Vec<u8>)
Source§impl Response
impl Response
Sourcepub fn content_type(&mut self, content_type: ContentType) -> &Response
pub fn content_type(&mut self, content_type: ContentType) -> &Response
Change Content-Type of the response
Source§impl Response
impl Response
Sourcepub fn add_header(&mut self, header: Header, value: String)
pub fn add_header(&mut self, header: Header, value: String)
Sourcepub fn add_multiple_headers(&mut self, headers: Vec<(Header, String)>)
pub fn add_multiple_headers(&mut self, headers: Vec<(Header, String)>)
Add multiple headers to response
§Examples
use pillow::http::*;
#[controller(method="GET", path = "/")]
fn index() {
let response: Response = Response::new_empty();
response.add_multiple_headers(vec![
(Header::ContentType, "text/html".to_string()),
(Header::AccessControlAllowOrigin, "*".to_string())
])
response
}Sourcepub fn get_headers(&self) -> String
pub fn get_headers(&self) -> String
Sourcepub fn clear_headers(&mut self)
pub fn clear_headers(&mut self)
Clear All headers
Sourcepub fn get_status_line(&self) -> String
pub fn get_status_line(&self) -> String
Get Status Line HTTP/1.1 200 OK
§Examples
let status_line: String = self.get_status_line();
assert_eq!(status_line, "HTTP/1.1 200 OK".to_string());Sourcepub fn set_status_code(&mut self, code: StatusCode)
pub fn set_status_code(&mut self, code: StatusCode)
Set Status Code Like 200 OK
§Examples
let response: Response = Response::new_empty();
response.set_status_code(StatusCode::Successfull(status_code::Successfull::OK));pub fn get_body(&self) -> Body
Trait Implementations§
impl Eq for Response
impl StructuralPartialEq for Response
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnwindSafe for Response
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more