Handling webhooks
Val Town is a very good fit for handling webhooks. You can create a val with an HTTP trigger and copy-paste its URL as a webhook destination.
What's a webhook?
A webhook is an event with some data, sent to some URL. Many apps send webhooks when something happens, like:
- A new Stripe subscription
- A star on a GitHub repo
- A comment on a Notion doc
Those apps—Stripe, GitHub, Notion, etc.—let you configure where to send webhooks. When an event happens, they will send an HTTP request to a URL you specify, and you can do whatever you want with that data.
Creating a webhook
While the specifics vary by service, the general steps are:
- Create an HTTP trigger to receive the webhook in Val Town
- Write some code to do something with incoming webhooks
- Copy-paste your val's URL into the sender app's configuration
- Secure the webhook by validating the request came from the app
To respond to a webhook, export a function from a file with an HTTP trigger:
export default function (req: Request): Response {
console.log(req.body);
return Response.json({ ok: true });
}Note: if your handler function awaits long-running tasks, you can early return
a 200 so that the sender won't retry the request.
Example
We have examples for receiving webhooks from GitHub, Stripe, and Supabase. But you could handle any webhook in Val Town. Let us know if there are specific integrations you'd like us to document!
Last updated