Hoverfly Cloud
Visit Our Main SitePricingTry Hoverfly Cloud
  • Introduction
  • Use cases for API Simulation
  • Key concepts
  • What's New
  • Dashboard
  • Simulation
    • Create simulations
    • Configuring Request Matchers
      • JSON Request Matchers on the Body
        • EXACT Matcher
        • JSON Matcher
        • JSON Partial Matcher
        • JSONPath Matcher
        • Regular Expression Matcher
      • Handling the response when Hoverfly cannot match
    • Building a JSON Response
      • Using a JSON object from the Request
      • Looping over a JSON array from the Request
    • Simulating Webhooks and Callbacks
    • Using templating in simulations
      • Render back any part of the Request
      • Render synthetic data
      • Faker functions
      • Render dates and times with offsets
      • Conditional logic
      • Looping over arrays
      • Variables and Arrays
      • Arithmetic operations
      • String operations
      • Validation operations
      • Simulating a persistent backend
      • Transitioning state between requests
      • Combining and nesting templating functions
      • Useful helper functions
      • Avoiding HTML encoding in function return values
    • Using data sources in simulations
      • Querying data sources
      • Updating data in data sources
      • Deleting data from data sources
      • Inserting data into a data source
      • Guidance on using the SQL like syntax
    • Working with Simulation Files
  • Service
    • Start a new service
    • Use a service
    • Update a service
    • Configuring Journal Indexing
  • Command line interface
    • Hoverfly Cloud CLI commands
  • Tutorials
    • Quickstart
    • Creating simulations and services
      • Tutorial 1: Create a service and simulation manually
      • Tutorial 2: Create a service and simulation by importing from a Swagger specification
      • Tutorial 3: Create a service and simulation by capturing real API traffic
    • Response Templating
      • Tutorial 4: Response Templating
    • Hoverfly service modes
      • Tutorial 5: Simulate, Capture, Spy and Passthrough modes
    • Automating with the CLI and API
      • Tutorial 6: Using the CLI and the Hoverfly Cloud API
Powered by GitBook
On this page
  • Example (Stripe payment confirmation):
  • Using templating within the callback
  1. Simulation

Simulating Webhooks and Callbacks

Simulate webhooks and callbacks with Hoverfly Cloud to test your application's integration with external services.

PreviousLooping over a JSON array from the RequestNextUsing templating in simulations

Last updated 3 months ago

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.

Example (Stripe payment confirmation):

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.

Using templating within 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