Prompt Library ⚙️ Technical Build a Webhook Handler from Scratch
GPT-4o ⚙️ Technical Intermediate

Build a Webhook Handler from Scratch

Build a secure, reliable webhook handler that verifies signatures, processes payloads, handles retries, and responds correctly to the sender.

👁 4 views ⎘ 0 copies ♥ 0 likes

The Prompt

# Build a Webhook Handler from Scratch

You are a backend engineer building a production-grade webhook handler.

## Webhook Context

Language/framework: [LANGUAGE_FRAMEWORK]
Webhook sender: [WEBHOOK_SOURCE] (Stripe, GitHub, Shopify, etc.)
Events to handle:
1. [EVENT_1]
2. [EVENT_2]
3. [EVENT_3]

## Implementation

Build a complete webhook handler with:

**1. Signature verification**
Write the signature verification code specific to [WEBHOOK_SOURCE]'s signing mechanism. This must run BEFORE processing the payload — fail fast on invalid signatures.

**2. Payload parsing**
Parse and validate the incoming JSON payload for each event type. Define the expected schema and reject malformed payloads.

**3. Event routing**
Route each event type to the appropriate handler function.

**4. Handler logic**
Write the handler for [EVENT_1]:
- What it does
- Database or side effects
- Error conditions

**5. Idempotency**
[WEBHOOK_SOURCE] may send the same event more than once. Implement idempotency using [IDEMPOTENCY_METHOD] to prevent duplicate processing.

**6. Response**
What HTTP status and body to return in each case:
- Success: [RESPONSE]
- Validation failure: [RESPONSE]
- Processing error: [RESPONSE]
- Unknown event type: [RESPONSE]

**7. Retry handling**
How does [WEBHOOK_SOURCE] handle retries? Design the handler to behave correctly when the same payload arrives again after a failure.

## Complete Code

Write the full implementation in [LANGUAGE_FRAMEWORK].

## Testing

Write 3 test cases with realistic [WEBHOOK_SOURCE] payloads.

📝 Fill in the blanks

Replace these placeholders with your own content:

[LANGUAGE_FRAMEWORK]
[WEBHOOK_SOURCE]
[EVENT_1]
[EVENT_2]
[EVENT_3]
[IDEMPOTENCY_METHOD]
[RESPONSE]

How to use this prompt

1
Copy the prompt

Click "Copy Prompt" above to copy the full prompt text to your clipboard.

2
Replace the placeholders

Swap out anything in [BRACKETS] with your specific details.

3
Paste into GPT-4o

Open your preferred AI assistant and paste the prompt to get started.