Currently Available: Need a skilled Software Developer for your next project?
Categories
APIs

Mapping Webhook Routing Rules to Your API Contract

When a provider sends a webhook, it directs an HTTP request to a configured URL. Providers and intermediaries use routing rules to decide which events go to that URL, and receiving services use them to sort events after they arrive. Because providers and intermediaries apply these rules in different ways, knowing the HTTP method and URL alone does not tell you which events will arrive.

If you want predictable delivery, you need to document the destination, the conditions that select events, and what each field in those conditions means. Once those rules control what a consumer receives, they become part of the API contract, even if the provider runs them on an internal event bus or rule engine.

Follow an event from destination to dispatch

Three decisions shape where a webhook goes and what happens to it. First, you or the provider set the destination URL. Second, the provider or an intermediary filters which events qualify for that URL. Third, the receiving service reads each incoming request and decides how to handle it.

Different systems handle these decisions in different places. GitHub lets subscribers pick categories of events for a configured webhook URL. When GitHub delivers a request, it includes an X-GitHub-Event header that names the category. The receiver can then inspect the payload, which holds the event data, to find a more specific action, such as an issue being opened or closed. GitHub recommends subscribing only to events the receiver plans to handle, and its event and payload documentation lists the available events and their payloads.

An intermediary can also filter events after it receives them. Amazon EventBridge evaluates events against rules on an event bus, a channel that receives events, and forwards each matching event to the destination configured for that rule. Because a single event can match more than one rule, an intermediary can send it to multiple destinations. That behavior differs from a provider sending requests directly to one URL configured by a subscriber. Check each provider's documentation rather than assuming it uses the same destination model or sends each event to only one place.

Separate event type from action or status

Webhook payloads often distinguish between three concepts. An event type names the broad kind of occurrence, such as an issue event. An action narrows that category to what happened, such as an issue being opened. A status usually describes a resource's state, such as whether an instance is running. Each provider defines these fields on its own, so a field named status does not carry the same routing behavior from one provider to another.

An EventBridge rule can check three parts of an event: its source, its detail-type, and the nested detail.state value. For a match to happen, the event must include those fields in those exact locations. EventBridge also uses exact, case-sensitive string matching for event patterns. Those rules are specific to EventBridge, so you need to check how another provider handles letter case, missing fields, and field values. See EventBridge event pattern syntax for its full pattern rules.

Standards give teams shared vocabulary, though they do not make every provider's filters interchangeable. The CloudEvents specification defines context fields such as type for the event type and source for where the event occurred. Optional fields like subject can identify the affected object. CloudEvents separates this metadata from the event data itself, allowing routing software to inspect the envelope without parsing the full payload. Meanwhile, the CloudEvents repository lists CloudEvents Subscriptions as work in progress. Treat it as a design reference rather than a widely adopted standard for subscription filters.

Describe the matching rules consumers depend on

A consumer needs enough detail in your contract to know which requests will arrive and how to read them. Start by documenting the configured destination and its scope, including which account, resource, or webhook context the subscription covers. Then list which event types qualify and whether an action, status, or another field narrows the match.

For every field that selects events, state where it lives and what its values mean. Specify whether the provider checks an HTTP header, an event envelope (the outer structure that wraps event data), or a field inside the payload. Explain how multiple conditions combine: must an event satisfy every condition, or only one? Spell out how the provider compares values, too. Note whether it is case-sensitive, requires an exact or partial match, accepts missing or null fields, or converts between data types. EventBridge requires fields at specific paths and compares strings exactly, which shows why a vague phrase like "matches the status" leaves consumers guessing.

Your contract should also show how the request body changes across events. Mark which fields are required, which are optional, and which appear only for certain event types or actions. State the event or schema version you are documenting, and tell consumers what to do when they receive an event type or action they do not recognize. Add concrete examples of events that match and events that fail to match, especially where a missing field or a change in letter case flips the outcome.

OpenAPI 3.1.1 can describe incoming webhook requests, including their headers, request bodies, and expected responses. On its own, however, OpenAPI does not define a provider's subscription settings or a general language for filtering events. Capture those selection rules in plain prose, schemas, examples, or a documented extension. For related contract concerns, see documenting webhook delivery semantics.

Treat observable selection as part of the API

When consumers cannot see which rule engine, event bus, or internal service layout a provider uses, those internals stay an infrastructure choice. Once the provider promises that specific event types, actions, or statuses will reach a documented endpoint, or that other events will be excluded, those selection rules become part of the API contract. Consumers build their handlers and validation around that promise. If the provider changes what a field means, how it compares values, or which events it selects, it changes the API's behavior even if the URL never changes.

Routing rules also do not prove where an event came from. For example, EventBridge warns that in its custom-bus subscriber filtering context, publishers can supply the source and detail-type values in the event data, so subscribers should not treat them as verified origin. Its documentation recommends using EventBridge-provided metadata for that filtering context instead. Your contract should state clearly whether a field only selects or describes an event, or whether the receiver can rely on it to verify the event's origin.

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Email updates

Usually a new article and a few links I found interesting.

No spam. Unsubscribe with one click.

Leave a Reply

Your email address will not be published. Required fields are marked *