Docs

Webhooks

A #[tool(webhook)] tool runs on each signed POST a sender makes, with the body as its arguments.

use berm_lang::{Result, tool};

/// Keeps the page a sender says changed.
#[tool(webhook)]
pub fn changed(url: String) -> Result<()> {
    let params = berm_lang::json::to(&[&url])?;
    berm_lang::sql("INSERT INTO changes (url) VALUES (?)", &params)?;
    Ok(())
}
  • The body is the tool's arguments, as a JSON object, and each parameter is a property of it.
  • It runs with no caller: berm_lang::caller() is empty.
  • It takes no access in crab.toml and cannot be public.
  • A service can have several, and they share one signing secret.
  • Its budget, logs and writes work as in any other tool.
  • A deploy that removes one, or takes webhook off it, is a breaking change.
  • A tool that fails answers the sender 500 with its message, and the sender decides whether to retry.
  • The tool sees the body and none of the headers. A sender can deliver the same event twice, so a tool that must not act twice keeps an id from the body.

On Cloud, a webhook reaches the tool only once its signature verifies. The local host's route takes no signature. See Webhooks.