Local Development Setup
Complete workflow for testing webhooks in your local development environment.
Development Environment Setup
1. Local Server Setup
// server.js
const express = require('express');
const app = express();
app.use(express.json());
app.post('/webhooks', (req, res) => {
console.log('🎉 Webhook received!');
console.log('Headers:', req.headers);
console.log('Body:', JSON.stringify(req.body, null, 2));
// Always respond with 200
res.status(200).json({
received: true,
timestamp: new Date().toISOString()
});
});
app.listen(3000, () => {
console.log('🚀 Local webhook server running on http://localhost:3000');
});
2. CLI Forwarding Setup
# Install CLI
npm install -g @hookvm/cli
# Start monitoring with forwarding
hookvm listen https://hookvm.com/hooks/your-endpoint-id \
--target http://localhost:3000/webhooks
3. Test the Setup
# Send test webhook
curl -X POST https://hookvm.com/hooks/your-endpoint-id \
-H "Content-Type: application/json" \
-d '{
"event": "test.local_development",
"message": "Testing local webhook setup",
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}'
Framework Examples
Next.js API Route
// pages/api/webhooks.js
export default function handler(req, res) {
if (req.method === 'POST') {
console.log('Webhook received:', req.body);
// Process webhook data
res.status(200).json({ success: true });
} else {
res.setHeader('Allow', ['POST']);
res.status(405).end(`Method ${req.method} Not Allowed`);
}
}
Express with TypeScript
import express, { Request, Response } from 'express';
interface WebhookPayload {
event: string;
data: any;
timestamp: string;
}
app.post('/webhooks', (req: Request<{}, {}, WebhookPayload>, res: Response) => {
const { event, data, timestamp } = req.body;
console.log(`Received ${event} at ${timestamp}`);
console.log('Data:', data);
res.status(200).json({ received: true });
});
Python Flask
from flask import Flask, request, jsonify
import json
app = Flask(__name__)
@app.route('/webhooks', methods=['POST'])
def handle_webhook():
data = request.get_json()
print(f"🎉 Webhook received: {json.dumps(data, indent=2)}")
# Process webhook data
return jsonify({"received": True}), 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3000, debug=True)
This section is under development. More local development patterns coming soon.