macro_rules! reply {
() => { ... };
(message => $message: expr, status => $status: expr) => { ... };
(json => $json: expr) => { ... };
(json => $json: expr, status => $status: expr) => { ... };
(sealed => $val: expr, key => $key: expr) => { ... };
(sealed => $val: expr, key => $key: expr, status => $status: expr) => { ... };
}Expand description
Convenience macro for constructing warp reply results inside route handlers.
| Syntax | Equivalent | Description |
|---|---|---|
reply!() | reply() | Empty 200 OK response. |
reply!(message => expr, status => Status::X) | reply_with_status | Plain reply with a status code. |
reply!(json => expr) | reply_with_json | JSON body with 200 OK. |
reply!(json => expr, status => Status::X) | reply_with_status_and_json | JSON body with a status code. |
reply!(sealed => expr, key => key) | reply_sealed | VEIL-sealed (or JSON for Plain) body, 200 OK. |
reply!(sealed => expr, key => key, status => Status::X) | reply_sealed_with_status | VEIL-sealed (or JSON for Plain) body with status. |
§Example
// Empty 200 OK
let ping = ServerMechanism::get("/ping")
.onconnect(|| async { reply!() });
// Plain reply with a custom status
let gone = ServerMechanism::delete("/v1")
.onconnect(|| async {
reply!(message => warp::reply::html("endpoint deprecated"), status => Status::Gone)
});
// JSON body, 200 OK
let list = ServerMechanism::get("/items")
.onconnect(|| async {
let items: Vec<Item> = vec![];
reply!(json => items)
});
// JSON body with a custom status
let create = ServerMechanism::post("/items")
.json::<Item>()
.onconnect(|item| async move {
reply!(json => item, status => Status::Created)
});