From 16eaca37eb6964d5a6d369fa5d267f84461318cd Mon Sep 17 00:00:00 2001 From: macdonst Date: Tue, 23 Jul 2024 13:26:40 -0400 Subject: [PATCH] Add snippet on webhooks Signed-off-by: macdonst --- app/docs/md/routing/api-routes/webhooks.md | 29 ++++++++++++++++++++++ app/docs/nav-data.mjs | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 app/docs/md/routing/api-routes/webhooks.md diff --git a/app/docs/md/routing/api-routes/webhooks.md b/app/docs/md/routing/api-routes/webhooks.md new file mode 100644 index 00000000..f28666a3 --- /dev/null +++ b/app/docs/md/routing/api-routes/webhooks.md @@ -0,0 +1,29 @@ +--- +title: Webhooks +--- + +A webhook is a method of augmenting or altering the behavior of a web page or web application with custom callbacks. + +You can use an API route to receive webhooks from third parties: + + + +```javascript +export async function post (req) { + try { + const data = req.body + // Process the webhook payload + // Validate payload, etc. + } catch (error) { + return { + status: 400, + } + } + + return { + status: 200, + } +} +``` + + diff --git a/app/docs/nav-data.mjs b/app/docs/nav-data.mjs index c9c44727..6747ab7f 100644 --- a/app/docs/nav-data.mjs +++ b/app/docs/nav-data.mjs @@ -59,7 +59,7 @@ export const data = [ path: '/docs/routing/api-routes/', label: 'API Routes', hasChildren: true, - items: [ 'middleware', 'tutorial' ], + items: [ 'middleware', 'tutorial', 'webhooks' ], }, ], },