Simulating Webhooks and Callbacks
Last updated
Last updated
You can configure Hoverfly Cloud simulations endpoints to make a call out to any HTTP endpoint after a given delay to simulate webhooks or callbacks.
The capability to make an HTTP callback to a real API after a configured delay following the activation of a simulation endpoint is a powerful feature of Hoverfly Cloud. This can be useful for simulating asynchronous workflows, delayed responses, or real-time event-driven architectures.
Callbacks are configured at the simulation level. They can be configured from simulations in the simulation library. They cannot be changed or configured on a simulation already running on a service. If a change is required it must be done to the master simulation, and then re-imported into the running service.
Up to 5 callbacks can be configured per simulation. Each endpoint (request/response pair) can elect whether or not to execute one of the 5 callbacks as required.
To illustrate the callback feature, consider an example where we need to simulate the Stripe API, and after a simulated payment is made, we need to simulate the webhook that Stripe executes to notify our test backend system of the payment status.
The request/response pairs we have configured might look like this:
After confirming the payment, the real Stripe API typically sends a webhook to a predefined endpoint (e.g. https://dev.pets-r-us.com/webhooks/stripe) to notify the application of the payment status.
We can configure a callback within this simulation to do exactly that:
We then associate this callback with the "Confirm a payment intent" endpoint. Then after a call to that endpoint is made, Hoverfly Cloud will make a call 1 second later to https://dev.pets-r-us.com/webhooks/stripe with the payload that you specify when configuring the callback.
Note that you can use handlebars templating to modify the query parameters, the header values and the content of the body if you choose to make the callback dynamic. This allows you to use the full scope of the templating engine as well as to include content from the original request. You can read about templating here