Stoobly Docs
  • Introduction
  • Use Cases
    • Generate Mock APIs
      • Empower Development
      • Scale API Testing
    • Enable E2E Testing
  • FAQ
    • Recording
    • Mocking
    • Terminology
  • Getting Started
    • Installing the Agent
      • Installation with pipx
      • Installation with Docker
  • Core Concepts
    • Agent
      • Intercept Modes
        • Mocking
        • Recording
      • Lifecycle Hooks
      • Proxy Settings
        • Data Rules
        • Firewall Rules
        • Rewrite Rules
        • Match Rules
    • Context
    • Mock API
      • Request
        • Response
        • Replay History
      • Scenarios
      • Snapshots
      • Fixtures
      • Public Folder
    • Scaffold
      • Service
      • Validation
      • Workflow
  • Guides
    • How to Run the Agent
      • Run with CLI
      • Run with Docker
    • How to Configure the Agent
      • Forward Proxy
        • Enable HTTPS Traffic
      • Reverse Proxy
    • How to Record Requests
      • Recording from the UI
      • Recording from the CLI
      • How to Create Contexts
      • How to Create Scenarios
        • Creating from the UI
        • Creating from the CLI
      • How to Create Requests
      • How to Customize Recordings
        • Customizing with Lifecycle Hooks
    • How to Update Requests
      • Editing from the UI
      • Editing with Snapshots
      • How to Update Scenarios
        • Updating from the UI
        • Updating from the CLI
      • Updating with Replay
        • Replaying from the UI
        • Replaying from the CLI
        • How to Customize Replays
          • Customizing with Lifecycle Hooks
      • Updating with Open API
    • How to Mock APIs
      • How to Enable Mocking
        • Enabling from the UI
        • Enabling from the CLI
      • How to Snapshot Requests
        • Deleting Snapshots
        • Sharing Snapshots
      • How to Use Fixtures
      • How to Customize Mocking
        • Customizing with Lifecycle Hooks
        • Customizing with Request Headers
      • Troubleshooting
    • How to Replay Requests
      • Replay with the UI
      • Replay with the CLI
    • How to Integrate E2E Testing
      • How to Scaffold an App
        • Scaffolding a Service
        • Customizing a Workflow
          • Customizing Container Services
          • Customizing Lifecycle Hooks
          • Customizing Init Scripts
          • Customizing Configure Scripts
          • Customizing Makefile
        • Troubleshooting
      • How to Run a Workflow
        • Running with CLI command
        • Running with Make
        • Troubleshooting
          • Validating
      • How to Stop a Workflow
        • Stopping with CLI command
        • Stopping with Make
      • How to Update a Scaffold
        • Deleting a Service
      • FAQ
  • Developer Guide
    • Installation from Source
    • Submitting Change Requests
    • Releases
  • Experimental
    • Experimental Features
      • Aliases
      • Endpoints
      • API Testing
        • Getting Started
        • Configuration
          • Assign
          • Lifecycle Hooks
          • Trace
      • Optional Components
Powered by GitBook
On this page
  • Why Mock APIs?
  • Current State of API Mocking
  • Creating
  • Maintaining
  • How Stoobly Helps
  • Creating Realistic Mocks
  • Scaling Maintenance
  • Getting Started
  • Create Mocks
  • Organize Mocks
  • Update Mocks
  • Sharing Mocks

Was this helpful?

  1. Use Cases

Generate Mock APIs

PreviousUse CasesNextEmpower Development

Last updated 4 months ago

Was this helpful?

Why Mock APIs?

Mocking out APIs results in faster and more reliable tests.

Tests that make requests to upstream APIs can suffer from intermittent failures due to updates or downtime. Because upstream APIs can also call other APIs, depending on live services tend to make tests slow. Having flaky and slow tests means more time is spent debugging and less time spent on core features.

Current State of API Mocking

Below we highlight two types of mock API's and provide examples for each:

  • Language specific libraries such as and

  • External mock servers such as and

In the following two sections, we list challenges with creating and maintaining API mocks. We then summarize how the challengs can be solved by using existing solutions.

Creating

Creating the initial API mocks is an upfront time cost by Software Engineers and QA Engineers.

The following lists challenges with creating API mocks and highlights existing solutions:

Creating realistic response stubs

Existing solutions:

  • Hard-coding responses

  • Use of faker libraries

Precisely matching requests with responses

Existing solutions:

  • Using strict or pattern-based URL matching to map requests to responses

  • Headers and bodies are not taken into account

Maintaining

Maintenance is a variable time cost by Software Engineers and QA Engineers. Every time the request or response contract changes, mocks have to be modified. This becomes a time-consuming process as more and more API endpoints are added. Time spent maintaining scales exponentially with the number of request variations.

The following lists challenges with maintaining mocks and highlights existing solutions:

  1. Determining which requests and responses need updating

    • Work with service maintainers

    • Audit change logs of upstream API changes

    • Wait for tests that depend on an out-of-date response to fail

  2. Updating mock request variations with up-to-date parameters and/or responses

    • Manually copy/paste or edit the request and/or response

How Stoobly Helps

A mock API works great from the time it is created to when it comes time for maintenance.

In order to generate mock APIs, we want to ensure that:

  • Request responses can be recorded instead of hard-coding

  • Precisely matching requests with responses

In order to maintain mock APIs, we want to ensure that:

  • Request responses can be refreshed without having to manually update each one

Creating Realistic Mocks

Stoobly makes creating realistic mocks fast and accessing them precise.

Recording

In comparison, to generate HTTP request mocks without recording:

1

Use a client driver (e.g. curl, browser) to send a HTTP request

2

Copy and paste the HTTP response into a mock tool or library

3

Repeat for different request variations and/or endpoints

We can see that this process quickly becomes difficult to scale. As either the number of HTTP request variations increase or as new endpoints are added, we have to keep manually adding responses to our mocks.

With recording, the process looks like:

  1. Configure a client driver (e.g. curl, browser) to proxy requests to Stoobly

  2. Send a HTTP request and let Stoobly record it for you

  3. Repeat for as many HTTP requests as you want

    1. e.g. rewriting any part of the request to filter sensitive data

Mocking

Stoobly comes out of the box with comprehensive request and response matching that should cover most use-cases without explicitly stating the match requirements. By default, Stoobly matches a HTTP request by looking for exact match of path, query params and body. If needed, match rules can be configured to relax or tighten matching requirements.

In comparison, to configure how HTTP requests are matched when mocking manually:

  1. Specify a exact path to match or use regex for pattern matching

  2. Repeat for every HTTP request that the mock API needs to support

An additional difficultly to highlight here is that matching bodies is often not possible. This is because the body would first have to be pared based on the specified content type.

With Stoobly mocking, the process looks like:

  1. Requests will be matched without additional configuration

    1. e.g. Matching based on specific query params and/or ignore headers

Scaling Maintenance

Stoobly helps minimize the impact of having to maintain mocks.

  1. Determining which requests and responses need updating

    • Shared maintenance, updates by producer can immediately be accessed by consumers

  2. Updating mock request variations with up-to-date parameters and/or responses

    • Support replaying requests and recording the responses

    • Group a sequence of requests into scenarios and batch replay and record

Without Stoobly

The process to update a HTTP response mock manually will look similar to:

  1. Determine which mocks need updating

  2. Use a client driver to resend a HTTP request

  3. Copy and paste the updated response

  4. Repeat for other mocks that need updating

While to above flow may not mirror exactly how mocks are always updated (sometimes we directly modify the mock), it serves to illustrates the difficutly in:

  1. Understanding which mocks need updating

  2. Understanding what a new correct version of the mock looks like

This problem gets even worse when we want to update a sequence of requests that have a relationship with each other (e.g. creating, reading, and deleting a resource are connected by the resource ID).

With Stoobly

The process can look similar to:

  1. Determine which requests or scenarios need updating

  2. Replay and record the requests or scenarios

Getting Started

Create Mocks

Organize Mocks

Update Mocks

Sharing Mocks

Stoobly lets you easily by recording HTTP traffic. To record traffic, Stoobly acts as a proxy between a client and server and intercepts traffic that passes through.

(Optional) Stoobly enables and .

(Optional) Stoobly enables . Matching against query params, body or headers can be either relaxed or tightened.

We empower you with the ability to and either overwrite the existing request response or alternatively, create a new version of the request. The following lists challenges with maintaining mocks and highlights manually:

Mockito
rspec-mocks
Wiremock
MirageJS
create mock APIs
configuration of which requests gets recorded
enables rewriting parts of a request
configuring how a request gets matched
replay recorded requests
How to Record Requests
How to Customize Recordings
How to Create Scenarios
How to Update Requests
How to Update Scenarios
How to Snapshot Requests