volga

Macro status

Source
macro_rules! status {
    (200) => { ... };
    (400) => { ... };
    (404) => { ... };
    ($status:expr, { $($json:tt)* }) => { ... };
    ($status:expr) => { ... };
    ($status:expr, [ $( ($key:expr, $value:expr) ),* $(,)? ]) => { ... };
    ($status:expr, $e:expr) => { ... };
}
Expand description

Produces a response with specified StatusCode with plain text or JSON body

§Examples

§Without body

use volga::status;

status!(404);

§plain/text body

use volga::status;

status!(401, "Unauthorized!");

§JSON body

use volga::status;
use serde::Serialize;
 
#[derive(Serialize)]
struct ErrorMessage {
    error: String
}
 
let error = ErrorMessage { error: "some error message".into() };
status!(401, error);