Skip to content

Commit 770e117

Browse files
committed
Updated structure and added an overview page
1 parent f9ea034 commit 770e117

File tree

4 files changed

+89
-34
lines changed

4 files changed

+89
-34
lines changed

docs/guides/frameworks/webhooks.mdx renamed to docs/guides/frameworks/nextjs-webhooks.mdx

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,15 @@
11
---
2-
title: "Setting up webhooks"
3-
sidebarTitle: "Webhooks"
4-
description: "Guides for using webhooks with Trigger.dev."
5-
icon: "webhook"
2+
title: "Triggering tasks with webhooks in Next.js"
3+
sidebarTitle: "Next.js webhooks"
4+
description: "Learn how to trigger a task from a webhook in a Next.js app."
65
---
76

8-
## Overview
9-
10-
Webhooks are a way to send and receive events from external services. Triggering tasks using webhooks allow you to add real-time, event driven functionality to your app.
11-
12-
A webhook handler is code that executes in response to an event. They can be endpoints in your framework's routing which will be triggered by an external service, for example.
13-
14-
In this guide you'll learn how to set up webhook handlers and trigger tasks from them using popular frameworks.
15-
16-
## Frameworks featured in this guide
17-
18-
- [Next.js](/guides/frameworks/webhooks#nextjs-webhook-configuration), pages or app router
19-
- [Remix](/guides/frameworks/webhooks#remix-webhook-configuration)
20-
21-
<Note>
22-
If you would like to see a webhook guide for your framework, please request it in our [Discord
23-
server](https://trigger.dev/discord).
24-
</Note>
25-
26-
## Next.js webhook configuration
27-
28-
### Prerequisites
7+
## Prerequisites
298

309
- [A Next.js project, set up with Trigger.dev](/guides/frameworks/nextjs)
3110
- [cURL](https://curl.se/) installed on your local machine. This will be used to send a POST request to your webhook handler.
3211

33-
### Adding a webhook handler
12+
## Adding a webhook handler
3413

3514
The webhook handler will be an API route. The location of the route file will be different depending on whether you are using the pages router or the app router.
3615

@@ -63,7 +42,7 @@ export async function POST(req: Request) {
6342
}
6443
```
6544

66-
### Triggering a task locally
45+
## Triggering a task locally
6746

6847
Now that you have a webhook handler set up, you can trigger the 'Hello World' task from it. We will do this locally using cURL.
6948

@@ -135,9 +114,3 @@ If you now go to your [Trigger.dev dashboard](https://cloud.trigger.dev), you sh
135114
</Step>
136115

137116
</Steps>
138-
139-
## Remix webhook configuration
140-
141-
### Prerequisites
142-
143-
- [A Remix project, set up with Trigger.dev](/guides/frameworks/remix)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: "Triggering tasks with webhooks in Remix"
3+
sidebarTitle: "Remix webhooks"
4+
description: "Learn how to trigger a task from a webhook in a Remix app."
5+
---
6+
7+
## Prerequisites
8+
9+
- [A Remix project, set up with Trigger.dev](/guides/frameworks/remix)
10+
- [cURL](https://curl.se/) installed on your local machine. This will be used to send a POST request to your webhook handler.
11+
12+
## Adding a webhook handler
13+
14+
The webhook handler will be an API route. Create a new file in `app/routes/api.webhook-handler.ts` or `app/routes/api.webhook-handler.js`.
15+
16+
In your new file, add the following code:
17+
18+
```ts /api/webhook-handler.ts
19+
import type { ActionFunctionArgs } from "@remix-run/node";
20+
import { tasks } from "@trigger.dev/sdk/v3";
21+
import { helloWorldTask } from "src/trigger/example";
22+
23+
// This function can handle GET requests to check if the webhook is active in the browser - not required for Trigger but helpful for testing
24+
export async function loader() {
25+
return new Response("Webhook endpoint is active", { status: 200 });
26+
}
27+
28+
// This function handles the actual webhook payload and triggers the helloWorldTask
29+
export async function action({ request }: ActionFunctionArgs) {
30+
const payload = await request.json();
31+
console.log("Received webhook payload:", payload);
32+
33+
// Trigger the helloWorldTask with the webhook data as the payload
34+
await tasks.trigger<typeof helloWorldTask>("hello-world", payload);
35+
36+
return new Response("OK", { status: 200 });
37+
}
38+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: "Using webhooks with Trigger.dev"
3+
sidebarTitle: "Overview"
4+
description: "Guides for using webhooks with Trigger.dev."
5+
---
6+
7+
## Overview
8+
9+
Webhooks are a way to send and receive events from external services. Triggering tasks using webhooks allow you to add real-time, event driven functionality to your app.
10+
11+
A webhook handler is code that executes in response to an event. They can be endpoints in your framework's routing which will be triggered by an external service.
12+
13+
## Webhook guides
14+
15+
<CardGroup cols={2}>
16+
<Card
17+
title="Next.js - triggering tasks using webhooks"
18+
icon="N"
19+
href="/guides/frameworks/nextjs-webhooks"
20+
>
21+
How to create a webhook handler in a Next.js app, and trigger a task from it.
22+
</Card>
23+
<Card
24+
title="Remix - triggering tasks using webhooks"
25+
icon="R"
26+
href="/guides/frameworks/remix-webhooks"
27+
>
28+
How to create a webhook handler in a Remix app, and trigger a task from it.
29+
</Card>
30+
</CardGroup>
31+
32+
<Note>
33+
If you would like to see a webhook guide for your framework, please request it in our [Discord
34+
server](https://trigger.dev/discord).
35+
</Note>

docs/mint.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,16 @@
286286
"guides/frameworks/supabase-edge-functions-database-webhooks"
287287
]
288288
},
289-
"guides/frameworks/webhooks"
289+
{
290+
"group": "Webhooks",
291+
"icon": "webhook",
292+
"iconType": "solid",
293+
"pages": [
294+
"guides/frameworks/webhooks-guides-overview",
295+
"guides/frameworks/nextjs-webhooks",
296+
"guides/frameworks/remix-webhooks"
297+
]
298+
}
290299
]
291300
},
292301
{

0 commit comments

Comments
 (0)