Andromeda
Note

Webhooks

Definition

A Webhook is a mechanism that allows one application to provide other applications with real-time information. It is often described as a “reverse API” or “HTTP push” because the server pushes data to the client’s URL automatically when a specific event occurs, rather than waiting for the client to poll for updates.

Why It Matters

Webhooks are significantly more efficient than polling (repeatedly asking “Is there new data?”). They enable real-time synchronization between systems (e.g., notifying a Slack channel when a GitHub commit is made or triggering a build when a payment is processed) without wasting server resources.

Core Concepts

  • Event-Driven: Triggered by specific actions (e.g., payment_received, file_uploaded).
  • Payload: The data sent in the HTTP POST request (usually JSON).
  • Callback URL: The destination URL provided by the client where the server sends the data.
  • Webhook vs. Polling:
    • Polling: Client asks server for data every X seconds.
    • Webhook: Server tells client “Here is the data” immediately after the event.
# Conceptual: A Flask endpoint acting as a Webhook receiver
from flask import Flask, request

app = Flask(__name__)

@app.route('/github-webhook', methods=['POST'])
def handle_webhook():
    data = request.json
    print(f"New event received: {data['event_type']}")
    return "OK", 200

Connected Concepts