πŸ“ Tutorials
Β· 2 min read

What is a Webhook? A Simple Explanation for Developers


A webhook is a way for one app to send data to another app the moment something happens.

Instead of your app constantly asking β€œdid anything change yet?” (that’s called polling), the other app just tells you when something happens. It’s like the difference between refreshing your email every 10 seconds vs. getting a push notification.

How it works

  1. You give App B a URL (your webhook endpoint)
  2. When something happens in App B, it sends an HTTP POST request to that URL
  3. Your server receives the data and does something with it

That’s it. A webhook is just a URL that receives POST requests.

Real-world examples

  • GitHub β†’ sends a webhook to your server every time someone pushes code
  • Stripe β†’ sends a webhook when a payment succeeds or fails
  • Discord β†’ you can send messages to a channel by POSTing to a webhook URL
  • Shopify β†’ sends a webhook when someone places an order

Webhook vs API

APIWebhook
Who initiates?You ask for dataThey send you data
DirectionYou β†’ themThem β†’ you
TimingWhenever you askWhen something happens
Also calledPullPush

Think of an API as β€œI’ll call you” and a webhook as β€œdon’t call me, I’ll call you.”

A simple example

Here’s a Discord webhook in action. Discord gives you a URL, and you POST a message to it:

curl -X POST "https://discord.com/api/webhooks/your-id/your-token" \
  -H "Content-Type: application/json" \
  -d '{"content": "Hello from a webhook!"}'

That’s a complete webhook call. Discord receives it and posts the message in your channel.

Receiving webhooks

If you want to receive webhooks (e.g., from GitHub or Stripe), you need a server with a public URL that can handle POST requests:

from flask import Flask, request

app = Flask(__name__)

@app.route("/webhook", methods=["POST"])
def handle_webhook():
    data = request.json
    print(f"Received webhook: {data}")
    # Do something with the data
    return "OK", 200

The key things to remember:

  • Webhooks are always POST requests
  • The data comes as JSON in the request body
  • You should return a 200 status code quickly (process heavy work in the background)
  • Always verify the webhook is legit (most services include a signature header)

When to use webhooks

Use webhooks when you need real-time reactions to events. Common use cases:

  • CI/CD pipelines β€” trigger a build when code is pushed (GitHub Actions uses this)
  • Payment processing β€” update your database when Stripe confirms a payment
  • Chat notifications β€” send alerts to Discord or Slack when something happens
  • Monitoring β€” get notified when your server goes down