Struct pillow_http::Response

source ·
pub struct Response {
    pub cors: String,
    /* private fields */
}
Expand description

Response to client

Fields§

§cors: String

Cross Origin Site

Implementations§

source§

impl Response

source

pub fn new_empty() -> Response

Returns a new Response

source§

impl Response

source

pub fn view(page: &'static str) -> Response

Send a html file from views directory

Arguments
  • page - A String that the page on views directory
Examples
use pillow::http::Router;

let mut app = Router::new();

app.get("/", |_, mut response| response.view("index"));
source

pub fn view_hbs(page: &'static str, data: Value) -> Response

Send a hbs file from views directory

Arguments
  • page - A String that the page on views directory
  • data - Json value
Examples
use pillow::json;
use pillow::http::Router;

let mut app = Router::new();

app.get("/", |_, mut response| {
    response.view_hbs("index", json!({"name": "foo"}))
});
source

pub fn json(js: Value) -> Response

Send a json from macro json!

Arguments
  • json - A string slice that sends to http client
Examples
use pillow::json;
use pillow::http::Router;

let mut app = Router::new();

app.get("/", |_, mut response| {
   let json = json!({
    "name": "Manuel"
    "age": 18
   })

   response.json(json)
source

pub fn json_from_str(json: &str) -> Response

Send a json from str

Arguments
  • json - A string slice that sends to http client
Examples
use pillow::http::Router;

let mut app = Router::new();

app.get("/", |_, mut response| response.json_from_str(r#"
{
    "name": "SummaryPuppet",
    "age": 18,
}
"#));
source

pub fn text(txt: &str) -> Response

Send text to client

Examples
fn (){
    app.get("/", |_, response| response.text("hello"));
}
source

pub fn css(&mut self, css: String) -> String

Send css response to client

source

pub fn javascript(&mut self, js: String) -> String

Send javascript to client

source§

impl Response

source

pub fn to_string(&self) -> String

source

pub fn insert_content(&mut self, content: String)

source§

impl Response

source

pub fn content_type(&mut self, content_type: ContentType)

source§

impl Response

source§

impl Response

source

pub fn add_header(&mut self, header: Header, value: String)

Add header to response

Arguments
  • header - Header name
  • value - Header value
Examples
use pillow::http::Router;

let mut app = Router::new();

app.get("/", |_, response| {
    response.add_header(Header::ContentType, "text/hmtl".to_string());
    response.view("index")
})
source

pub fn add_multiple_headers(&mut self, headers: Vec<(Header, String)>)

Add multiple headers to response

Examples
use pillow::http::Router;

let mut app = Router::new();

app.get("/", |_, response|{
    response.add_multiple_headers(vec![
        (Header::ContentType, "text/html".to_string()),
        (Header::AccessControlAllowOrigin, "*".to_string())
    ])

    response.view("index")
})
source

pub fn clear_headers(&mut self)

Clear All headers

source

pub fn set_status_code(&mut self, code: StatusCode)

Set Status Code Like 200 OK

Trait Implementations§

source§

impl Debug for Response

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V