How Hoverfly Cloud tackles stateful API workflows

3 min read
Oct 14, 2025 10:46:02 AM

Beyond the mock: Simulating complex, stateful API workflows with Hoverfly Cloud

From user sessions to multi-step transactions, learn how to reliably test your application’s interaction with dependent APIs using Hoverfly Cloud.

Why stateful APIs are a testing head-scratcher

With interconnected software development, especially within a microservice architecture, APIs are rarely simple, stateless interactions. A real-world workflow often involves a sequence of calls where the response to one request is dependent on the result of a previous one. Think of a classic e-commerce checkout:

  1. POST /basketReturns a basketId
  2. POST /payment/authorise (with basketId) → Returns a transactionId
  3. POST /order/submit (with transactionId) → Returns a 201 Created

If your testing environment or a third-party payment gateway is unavailable, unstable, or too costly to use for high-volume testing, simulating this stateful journey becomes a significant challenge. Traditional mocks are typically limited to simple request-response matching, falling short when the internal state of the simulated service needs to evolve.

Building a persistent backend simulation with Hoverfly Cloud

This is where Hoverfly Cloud’s advanced simulation features shine, allowing dev and QA teams to create highly realistic, stateful mocks. The key is in its ability to introduce persistence and dynamic response generation.

  1. Persistent backend simulation (The “In-memory journal”)

An important feature of Hoverfly Cloud is its capacity to simulate a persistent backend. It achieves this by logging and making previous request-response pairs accessible from its internal, in-memory journal. This transforms a stateless mock into a dynamic, state-aware one.

  • How it works: When a request is made, the simulation logic can look up a value saved from an earlier request within the same test flow. For instance, the POST to /basket can generate a unique basketId and save it. The subsequent POST to /payment/authorise then checks the journal to see if the required basketId exists and is valid before proceeding.
  • The benefit: Your application under test sees a consistent, step-by-step transaction, mirroring the logic of the real system without the need for an actual database or third-party service.
  1. Dynamic responses with response templating

Stateful workflows often require dynamic data, such as a generated token, a unique transaction ID, or a timestamp that is then re-used or validated in a subsequent request.

Hoverfly Cloud uses powerful Handlebars templating to inject logic and dynamic values directly into the response body or headers.

Scenario

Hoverfly Cloud Technique

Extract and Re-use

Use the templating language to capture an element from the Request (e.g., a session ID from a header) and include it in the Response body.

Generate Unique IDs

Utilise built-in functions (like those from the Go-Faker library) to generate realistic, synthetic data on the fly (e.g., a valid-looking UUID, a location postcode, or a future date).

Conditional Logic

Employ conditional logic (#if, #equal) to serve different responses based on the request’s content. For a stateful scenario, this means an API could return a 404 Not Found if a required transactionId is missing or invalid.

 

The advantage: Accelerating CI/CD

In high demand sectors such as financial services and e-commerce, time-to-market is everything. Simulating stateful workflows with Hoverfly Cloud directly translates to business agility:

  • Eliminate Rate Limits and Costs: Stop paying for or being restricted by calls to live, third-party APIs during massive load tests or daily development cycles.
  • Test Edge Cases Reliably: Easily simulate complex, hard-to-replicate state transitions like a payment timing out after two steps, or a specific user session becoming invalid—scenarios you simply cannot force in a production-like environment.
  • Shift-Left Development: Developers can begin building and testing client logic against an API contract before the backend team has even finished developing the real state logic, enabling true parallel development.

Master stateful testing

If your team is struggling to reliably test complex transactions due to external API dependencies, Hoverfly Cloud offers a robust, cloud-hosted solution to bring consistency, control, and state awareness back to your development pipeline.

Find out more today and put us to the test. Request a demo to see how easy it is to simulate your most complex stateful workflows.

Boost API simulation and put Hoverfly Cloud to the test

 

Get Email Notifications