Struct canteen::response::Response
[−]
[src]
pub struct Response { /* fields omitted */ }
This struct reprsents the response to an HTTP client.
Methods
impl Response
[src]
fn new() -> Response
[src]
Create a new, empty Response.
fn as_json<T: Serialize>(data: &T) -> Response
[src]
Creates a Response with a JSON body
Examples
⚠Be careful when using this code, it's not being tested!
use canteen::Response; user serde::Serialize; #[derive(Serialize)] struct Foo { item: i32, } let foo = Foo { item: 12345 }; let res = Response::as_json(&foo);
fn set_status(&mut self, status: u16)
[src]
Sets the response status for the HTTP response.
Examples
use canteen::Response; let mut res = Response::new(); res.set_status(200);
fn set_content_type(&mut self, ctype: &str)
[src]
Sets the Content-Type header for the HTTP response.
Examples
use canteen::Response; let mut res = Response::new(); res.set_content_type("text/html");
fn add_header(&mut self, key: &str, value: &str)
[src]
Adds a header to the HTTP response.
Examples
use canteen::Response; let mut res = Response::new(); res.add_header("Content-Type", "text/html");
fn append<T: ToOutput>(&mut self, payload: T)
[src]
Appends data to the body of the HTTP response. The trait ToOutput must be implemented for the type passed.
Examples
use canteen::Response; let mut res = Response::new(); let data = "{ message: \"Hello, world!\" }"; res.append(data);
fn gen_output(&self) -> Vec<u8>
[src]
Returns a byte array containing the full contents of the HTTP response, for use by the Canteen struct.