Webhooks Documentation

Webhooks provide a real-time, automated way to respond to events in your applications. Instead of repeatedly polling for updates, your application can register a webhook endpoint, and other services will push data to that endpoint when an event occurs.

What are Webhooks?

Think of a webhook like a notification. When a specific event happens in a service (e.g., a new user is created, a payment is made, a message is sent), that service automatically sends a notification to your webhook endpoint. This allows you to react to those events immediately without any manual intervention.

How Webhooks Work

  1. Register a Webhook Endpoint: You'll need to create an endpoint (a URL) that your service can call. This is typically a REST API endpoint.
  2. Event Trigger: An event occurs in the service you're integrating with.
  3. Data Transmission: The service sends data related to the event to your webhook endpoint. This data is usually formatted as JSON.
  4. Response: Your application processes the data and performs the appropriate action.

Example: GitHub Webhooks

GitHub provides a popular example of webhooks. When a push event occurs on a repository, GitHub automatically sends a webhook to your application, allowing you to automate tasks like deploying code, running tests, or sending notifications.

Example JSON Payload (GitHub Push Webhook)


{
  "head_commit": {
    "id": "a1b2c3d4e5f67890...",
    "message": "Fix: Resolved issue #123",
    "author": {
      "name": "John Doe",
      "email": "john.doe@example.com"
    }
  },
  "ref": "refs/heads/main",
  "repository": {
    "name": "my-repo",
    "full_name": "john.doe/my-repo"
  }
}

Best Practices