Overview
Protocol: HTTPS POST callbacks Pattern: Event-driven (Server → Client) Direction: Unidirectional (Server calls your endpoint) When to Use Webhooks:- ✅ Real-time event notifications
- ✅ Order status updates
- ✅ Payment confirmations
- ✅ Pet adoption notifications
- ✅ Inventory alerts
- ❌ You need to request data (use REST instead)
- ❌ Your endpoint is not publicly accessible (use polling instead)
How Webhooks Work
- Server initiates the request
- Push-based (no polling needed)
- Event-driven architecture
- HMAC signature verification
- Automatic retry on failure
Webhook Events
Pet Events
Pet Adopted
Pet Status Changed
Order Events
Order Created
Order Status Changed
Payment Events
Payment Succeeded
Payment Failed
Setting Up Webhooks
1. Register Your Webhook URL
2. Create Webhook Endpoint
3. Test Your Webhook
Signature Verification
Why Verify Signatures?
- ✅ Ensure webhook is from Petstore API
- ✅ Detect tampering
- ✅ Prevent fraud
Verification Process
Best Practices
1. Always Return 200 OK Quickly
2. Handle Duplicate Events
3. Retry Logic
The API will retry webhooks that fail:| Attempt | Delay |
|---|---|
| 1 | Immediate |
| 2 | 1 minute |
| 3 | 5 minutes |
| 4 | 30 minutes |
| 5 | 1 hour |
4. Idempotency
Make your webhook handlers idempotent:Security
1. Use HTTPS
Always use HTTPS for your webhook endpoint.2. Verify Signatures
Never process webhook events without signature verification.3. Validate Payloads
4. Rate Limiting
Managing Webhooks
List Webhooks
Get Webhook Details
Update Webhook
Delete Webhook
Troubleshooting
Not Receiving Webhooks
- Check webhook status is
active - Verify endpoint URL is publicly accessible
- Confirm HTTPS certificate is valid
- Check server logs for connection attempts
- Test with webhook test endpoint
Signature Verification Fails
- Ensure you’re using the correct secret
- Verify you’re comparing the entire signature
- Check for encoding issues
High Failure Rate
- Ensure endpoint responds quickly (< 5 seconds)
- Always return 200 OK (even if processing fails later)
- Implement retry logic in your application
- Monitor endpoint uptime
Comparison with Alternatives
| Feature | Webhooks | Polling | WebSocket |
|---|---|---|---|
| Latency | Very Low | High | Very Low |
| Server Load | Low | High | Medium |
| Complexity | Low | Low | High |
| Public Endpoint | Required | Not Required | Required |
| Real-time | ✅ | ❌ | ✅ |
Interactive Documentation
- API Specification: OpenAPI 3.2
- Webhooks in OpenAPI: See webhooks section
- Protocol Overview: All Protocols
Related Resources
- AsyncAPI Specification
- REST API Guide - For request/response patterns
- Quick Start Guide