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
  • Capture real service activities
  • Manual design using the Simulation Editor
  • Convert from a Swagger Specification
  • Upload from an existing simulation file
  • Learn more
  1. Simulation

Create simulations

Create and manage API simulations with Hoverfly Cloud, capturing real service activity for robust testing.

PreviousSimulationNextConfiguring Request Matchers

Last updated 3 months ago

Capture real service activities

Capturing live traffic of a real service is a quick way to create a simulation.

You can do that on Hoverfly Cloud if the service is available on the internet. Otherwise, if the service is behind a firewall and Hoverfly Cloud has no access to it, you will need to use .

Let's take a look at how you can capture one of the end points from the . The base URL for the API is https://dog.ceo.

In the Simulations page, click the "Capture" button, and select "Yes" to confirm that the API you are going to capture is accessible from the internet.

Then you will be prompted to enter the base URL of the target API.

Click "OK", and a capture service will start on the Dashboard.

You should make your requests to the capture service URL instead of the original URL. For example, the original URL for getting a random dog image URL is:

https://dog.ceo/api/breeds/image/random

What you should call instead in this example is:

https://dog-ceo-stuawj8.hoverfly.io/api/breeds/image/random

You can inspect the requests and responses that have been captured by clicking on the unsaved simulation link. You will see that an endpoint has created to represent the request and a matching response.

The captured simulation can be edited and exported for future use and sharing. It can also be turned into a simulation so that it plays back the responses based on matching requests it receives.

Run the following command to start a capture service on localhost:

hcc capture start --target-url https://dog.ceo

You should provide the base URL of the service to the destination flag.

Once the capture service is started, any requests you made to http://localhost:8500 will be forwarded to the real service and the requests/responses will be recorded.

You can stop the capture and upload your simulation to your Hoverfly Cloud account with the following command:

hcc capture stop --simulation-name NAME --api-token TOKEN

An API token can be created from your account page.

Manual design using the Simulation Editor

If your API does not yet exist, you can design it using the Simulation Editor. On the Simulations page, click “Create”.

Click on “Add endpoint” to add your first request/response pair.

Use the editor to design the request you want to match and the corresponding response. For example, a simple request matcher for matching GET request to the path /api/breeds/image/random should look like this:

You can click on the “duplicate” burger menu item to reuse an existing pair.

Once you are happy about your simulation, you can click “Save” to create it.

Changes made in the Simulation Editor are not automatically saved. You should click "Save" if you need to keep your changes before navigating to other pages.

Convert from a Swagger Specification

Click “From Swagger” to create a simulation from a Swagger Specification.

The current supported Swagger version is 2.0. Both JSON and YAML formats are supported.

Click “Choose file” and select a Swagger file from disk.

Click "Confirm" to finish.

Only one response per API specification is converted, which is usually the 200 successful response. The conversion will look for any example data to use for the response body, but if none were defined in the Swagger specification, Hoverfly Cloud will render a response body that conforms with the Swagger data schema.

Order{
    id	        integer($int64)
    petId	    integer($int64)
    quantity    integer($int32)
    shipDate	string($date-time)
    status	    string
                Order Status
                Enum:
                [ placed, approved, delivered ]
    complete	boolean
                default: false
}

Which converts to the following response body by Hoverfly Cloud:

{
  "id": 0,
  "petId": 0,
  "quantity": 0,
  "shipDate": "2000-01-01T00:00:00Z",
  "status": "placed",
  "complete": false
}

You can enhance the simulation converted from Swagger by using response templating.

Add templating functions to the above response and enable templating:

You should get back a response generated dynamically when you call the endpoint /v2/store/order/1:

{
  "id": 1,
  "petId": 156,
  "quantity": 3,
  "shipDate": "2019-05-20T13:35:08Z",
  "status": "placed",
  "complete": false
}

Upload from an existing simulation file

Learn more

Follow these tutorials to learn more about creating Simulations: Creating simulations and services

Hoverfly Cloud will create one request matcher for each combination of API path and operation in the specification. For example, the will be converted to the following matcher:

For instance, the defines the following response data schema:

Hoverfly Cloud simulation files are interchangeable with . To upload a simulation file go to the Simulations page, and click "Upload", select a file and click "Confirm".

Download the CLI here.
Swagger Petstore GET store order API
Swagger Petstore GET store order API
Hoverfly
the Hoverfly Cloud CLI
Dog CEO API