Macro ok

Source
macro_rules! ok {
    () => { ... };
    ([ $( ($key:expr, $value:expr) ),* $(,)? ]) => { ... };
    ({ $($json:tt)* }) => { ... };
    { $($name:tt : $value:tt),* $(,)? } => { ... };
    ({ $($json:tt)* }, [ $( ($key:expr, $value:expr) ),* $(,)? ]) => { ... };
    ($var:ident) => { ... };
    ($body:expr, [ $( ($key:expr, $value:expr) ),* $(,)? ]) => { ... };
    ($fmt:tt) => { ... };
    ($body:expr) => { ... };
    ($($fmt:tt)*) => { ... };
}
Expand description

Produces an OK 200 response with plain text or JSON body

§Examples

§plain/text

use volga::ok;

ok!("healthy");

§plain/text without body

use volga::ok;

ok!();

§JSON

 use volga::ok;
 use serde::Serialize;

 #[derive(Serialize)]
 struct Health {
    status: String
 }

 let health = Health { status: "healthy".into() };
 ok!(health);

§Untyped JSON with custom headers

 use volga::ok;
 use serde::Serialize;

 #[derive(Serialize)]
 struct Health {
    status: String
 }

 ok!({ "health": "healthy" }, [
    ("x-api-key", "some api key")
 ]);