Testing Webhooks Locally
Learn how to test webhook integrations on your local development environment using our CLI tool's forwarding capabilities.
Overview
Local webhook testing allows you to:
- Receive real webhooks on your local development server
- Debug webhook handlers in your IDE
- Test integrations before deploying to production
- Iterate quickly without deploying every change
Prerequisites
- Webhook endpoint created in your dashboard
- CLI tool installed (installation guide)
- Local development server running your webhook handler
Setup Process
1. Start Your Local Server
Make sure your local application is running and can handle webhook requests:
# Example for different frameworks
npm run dev # Next.js/React
rails server # Rails
python manage.py runserver # Django
node server.js # Node.js
Your local server should be listening on a port (e.g., http://localhost:3000).
2. Create a Webhook Handler
Ensure you have an endpoint that can receive POST requests:
Node.js/Express Example
app.post('/webhooks', (req, res) => {
console.log('Webhook received:', req.body);
// Process the webhook data
const event = req.body;
// Always respond with 200 OK
res.status(200).send('OK');
});
Python/Flask Example
@app.route('/webhooks', methods=['POST'])
def handle_webhook():
event = request.get_json()
print(f"Webhook received: {event}")
# Process the webhook data
return '', 200
Next.js API Route Example
// pages/api/webhooks.js
export default function handler(req, res) {
if (req.method === 'POST') {
console.log('Webhook received:', req.body);
// Process the webhook data
const event = req.body;
res.status(200).json({ received: true });
} else {
res.setHeader('Allow', ['POST']);
res.status(405).end(`Method ${req.method} Not Allowed`);
}
}
3. Start CLI with Forwarding
Connect to your webhook endpoint and forward events to your local server:
hookvm listen https://hookvm.com/hooks/your-endpoint-id \
--target http://localhost:3000/webhooks
You should see output like:
📡 Monitoring: https://hookvm.com/hooks/your-endpoint-id
📋 Endpoint ID: your-endpoint-id
🎯 Target URL: http://localhost:3000/webhooks
✓ WebSocket connected to webhook events
🚀 Webhook monitor is now active!
Endpoint: https://hookvm.com/hooks/your-endpoint-id
Forwarding to: http://localhost:3000/webhooks
Testing Workflow
1. Send Test Events
Use your service's webhook testing feature or send manual test events:
From Your Service (e.g., Stripe)
- Go to your service's webhook dashboard
- Find your endpoint
- Click "Send test event"
- Select an event type and send
Manual Test with curl
curl -X POST https://hookvm.com/hooks/your-endpoint-id \
-H "Content-Type: application/json" \
-d '{
"event": "test.payment",
"amount": 2000,
"currency": "usd"
}'
2. Monitor in CLI
Watch the real-time event flow in your CLI:
🟢 POST / [12:34:56] → ✅ 200
├── 📥 Received (webhook-service)
└── 📤 Forwarded → localhost:3000 (✅ 200 OK)
3. Debug in Your IDE
- Set breakpoints in your webhook handler
- Inspect the webhook payload
- Step through your processing logic
- Test error scenarios
Advanced Forwarding
Multiple Handlers
Forward to different local endpoints based on event type:
# Terminal 1 - Payment events
hookvm listen https://hookvm.com/hooks/payment-endpoint \
--target http://localhost:3000/webhooks/payments
# Terminal 2 - User events
hookvm listen https://hookvm.com/hooks/user-endpoint \
--target http://localhost:3000/webhooks/users
Custom Headers
Add authentication or custom headers to forwarded requests:
hookvm listen https://hookvm.com/hooks/your-endpoint-id \
--target http://localhost:3000/webhooks \
--header "Authorization: Bearer your-local-token" \
--header "X-Environment: development"
HTTPS Local Server
If your local server uses HTTPS:
hookvm listen https://hookvm.com/hooks/your-endpoint-id \
--target https://localhost:3443/webhooks
Debugging Common Issues
Local Server Not Responding
Symptoms: CLI shows "forwarding failed" or timeout errors
Solutions:
- Check server is running: Verify your local server is running on the specified port
- Test endpoint directly:
curl -X POST http://localhost:3000/webhooks \
-H "Content-Type: application/json" \
-d '{"test": true}' - Check firewall: Ensure no firewall is blocking the connection
Wrong Handler Path
Symptoms: Getting 404 errors on forwarded requests
Solutions:
- Verify the path: Make sure
/webhooks(or your path) exists in your local app - Check routing: Ensure your routes accept POST requests
- Test with browser: Visit
http://localhost:3000/webhooksto see if the route exists
Handler Errors
Symptoms: CLI shows forwarding succeeded but handler has errors
Solutions:
- Check application logs: Look for errors in your local server logs
- Add error handling: Ensure your handler has proper error handling
- Return proper status: Always return HTTP 200 for successful processing
Network Issues
Symptoms: Cannot connect to webhook endpoint
Solutions:
- Check internet connection: Ensure you can reach the webhook service
- Verify endpoint URL: Make sure the endpoint URL is correct
- Check firewall: Ensure WebSocket connections are allowed
Best Practices
Development Workflow
- Start local server first before starting CLI forwarding
- Use consistent ports across your development team
- Version control webhook handlers like any other code
- Test error scenarios not just successful cases
Security Considerations
- Use test endpoints for development, not production endpoints
- Don't commit sensitive data received via webhooks
- Implement signature verification even in development
- Use HTTPS for production-like testing
Performance Testing
- Test with high volume: Use tools to send multiple rapid webhooks
- Monitor response times: Ensure handlers respond quickly (< 30s)
- Test concurrent requests: Multiple webhooks arriving simultaneously
- Handle backpressure: What happens when your handler is slow?
Integration Examples
E-commerce Order Processing
app.post('/webhooks/orders', (req, res) => {
const order = req.body;
switch(order.event) {
case 'order.created':
console.log(`New order: ${order.id}`);
// Update inventory, send confirmation email
break;
case 'order.shipped':
console.log(`Order shipped: ${order.id}`);
// Send tracking info to customer
break;
case 'order.cancelled':
console.log(`Order cancelled: ${order.id}`);
// Restore inventory, process refund
break;
}
res.status(200).send('OK');
});
Payment Processing
app.post('/webhooks/payments', (req, res) => {
const payment = req.body;
if (payment.event === 'payment.succeeded') {
// Mark order as paid
markOrderPaid(payment.order_id);
// Send receipt email
sendReceiptEmail(payment.customer_email, payment);
// Update analytics
trackPaymentSuccess(payment.amount);
}
res.status(200).send('OK');
});
Next Steps
Once you've tested locally:
- Deploy to staging with real webhook endpoints
- Set up monitoring for production webhook handling
- Configure alerting for webhook failures
- Document your integration for your team
Ready for production? Learn about webhook security and best practices.