Skip to main content

Module reply

Module reply 

Source
Expand description

What a hook handler returns to the host.

A hook’s Ok value is a JSON object the host reads as an instruction. These helpers build it; anything else (including {} or null) means “carry on unchanged”, so an observational hook can simply return Ok(serde_json::Value::Null).

fn guard(ctx: &Context<()>, _input: serde_json::Value) -> Result<serde_json::Value, String> {
    let Some(h) = ctx.hook() else { return Ok(reply::proceed()) };
    if h.field("title").and_then(|t| t.as_str()).unwrap_or("").is_empty() {
        return Ok(reply::abort(422, "title is required"));
    }
    Ok(reply::proceed())
}

Functions§

abort
Abort the request with an HTTP status and message. Statuses outside 400..=599 are clamped to 400 by the host.
proceed
Continue with the payload unchanged.
replace
Replace the payload (before_create/before_update) or the response body (any after_* hook) with data.