macro_rules! response { (ok) => { ... }; ($type:ident) => { ... }; ($type:ident,$body:expr) => { ... }; ($type:ident,$body:expr,$headers:expr) => { ... }; ($type:ident,$body:expr,$headers:expr,$http_version:expr) => { ... }; }
Expand description
A quick way to create responses.
Usage:
use snowboard::{response, HttpVersion, headers};
use std::collections::HashMap;
// Response with no headers and no body.
let response = response!(bad_request);
// Response with body and no headers.
// Note that $body requires to implement `Into<Vec<u8>>`.
let response = response!(internal_server_error, "oopsies");
// Response with body, headers and custom HTTP version.
let body = "everything's fine!";
let headers = headers! {
"Content-Type" => "text/html",
"X-Hello" => "World!",
"X-Number" => 42,
};
let response = response!(ok, body, headers, HttpVersion::V1_0);
See headers! for more information about the headers macro.