1. What is a Webhook?
A webhook is a way for one service to notify another service automatically when an event happens.
- It’s like a phone call from one app to another, telling it: “Hey! Something just happened—here’s the data!”
Unlike APIs where you ask for data (pull), webhooks are push-based—the sender pushes the data to you when an event occurs.
2. How Webhooks Work
- You register a URL (your webhook endpoint) with a service.
- The service detects an event (e.g., a new order, a payment success).
- It sends an HTTP request (usually POST) to your URL with event data.
- Your service receives the data and processes it immediately.
3. Real-Life Analogy
- You order food online.
- Instead of constantly calling the delivery app to check the status, the app sends you a message when the food is picked up or delivered.
- That “message” is like a webhook.
4. Example Use Cases
| Event Source | Webhook Example |
|---|---|
| GitHub | Notify your CI/CD server when new code is pushed |
| Stripe/PayPal | Notify your server when a payment is completed |
| Twilio | Notify your server when an SMS is received |
| Slack | Receive messages/events in your app automatically |
5. Key Points
- Webhooks are push-based, unlike APIs which are usually pull-based.
- They use standard HTTP requests (POST is most common).
- Your service must expose a public endpoint to receive the webhook.