Skip to main content

Mock Server


The Mock Server feature in Sparrow enables developers and testers to simulate API behavior without requiring a live backend. This is essential for rapid prototyping, frontend-backend decoupling, and efficient QA testing workflows.

Mock servers behave just like real servers—responding to API requests with predefined data, based on request methods, parameters, headers, and even body content.

Sparrow makes mocking intuitive and powerful by combining ease-of-use with features like multi-response support, request logs, and folder organization.

Why Use a Mock Server?

Mock Servers are particularly useful when:

  • The backend is still under development
  • You want to test error conditions or alternate flows
  • APIs are not stable or are rate-limited
  • You want to quickly demonstrate or prototype a frontend app

With Sparrow, you can configure mock collections, mock requests, and simulate different response scenarios—without writing a single line of server-side code.

Getting Started with Mocking

Creating a Mock Collection

To begin mocking:

  1. Go to the Workspace view in Sparrow.

  2. Click on Collections → Choose + Add Mock Collection. You can also add a Mock Collection from the more options against Collections or + icon at the top.

    MockServer

  3. Give your collection a name from the RHS panel created or using the more options. Additionally you can provide a description, copy the mock URL, Run Mock or add new folder/mock REST API.

    MockServer

  4. The collection will appear in the sidebar with a grey Mock tag, indicating it’s currently inactive.

Once created, you can start adding mock requests to simulate API responses.

Activating and Deactivating a Mock Collection

  • Activation:

    • Click on the "Run Mock" action icon on the collection or the Run Mock button from the mock collection. This will inturn turn the mock collection from grey to green.
    • The collection is now hosted locally and will serve requests as defined.

    MockServer

  • Deactivation:

    • Click the stop icon against the collection or the Stop Mock button at the mock collection level where you had turned it on.
    • The tag turns grey and the mock server stops responding.

Use activation toggling to control which collections are live during testing.

Working with Mock Requests

Adding a Mock Request

  1. Right-click or open the ... menu in a mock collection.

  2. Select Add Mock REST API. You can also create a mock request with the help of the API request icon.

    MockServer

  3. Define:

    • HTTP Method (GET, POST, etc.)
    • Request Path (e.g., /api/login)
    • Optional: Headers and Body
  4. Define the response:

    • Status code (e.g., 200 OK)
    • JSON body and other needed parameters

    MockServer

Click Save and optionally Send to preview the mock response instantly post clicking on the Try button.

Creating Multiple Responses for a Request

You can simulate different outcomes for a single endpoint using Multi-Response Mode.

Use Cases:

  • Different responses based on environment headers
  • Simulate success/failure conditions
  • Validate client-side behavior under varying outputs

Steps:

  1. Open a mock request.

  2. Click + Add Response.

    MockServer

  3. Define conditions you need for the response.

  4. Responses are evaluated based on the toggle.

Assigning Mock Ratios

Sparrow allows you to assign response ratios when you have multiple mock responses configured for a single endpoint. This is especially useful when simulating randomized behavior or probabilistic testing scenarios.

What is a Mock Ratio?

A mock ratio defines how often a particular mock response should be served relative to others, based on weight. It is expressed as a numeric value that indicates its relative probability.

For example:

  • Response A: 70
  • Response B: 30

This means:

  • Response A will be served ~70% of the time
  • Response B will be served ~30% of the time

When to Use Ratios?

  • To test how your application handles different types of responses randomly
  • For simulating flaky APIs or error rate testing
  • For load testing different success/failure paths

How to Assign Ratios?

  1. Open a mock request.

  2. Click the Set Response Ratios icon beside Add Mock response icon in the responses section.

  3. Locate the Ratio field.

  4. Enter the desired number (e.g., 60, 40).

  5. Ensure that all ratios add up to a reasonable total. The system uses relative weights, so it's okay if the sum is not 100.

    MockServer

Organizing with Folders

Creating Folders in a Mock Collection

Folders help logically group your mock requests, especially for larger projects.

  1. Click on the ... menu of a mock collection.
  2. Select Add Folder. You can additionally create a folder with the help of folder icon.
  3. Name the folder and start adding or moving requests into it.

Benefits:

  • Easier navigation and clarity
  • Supports team collaboration and better scoping
  • Maintains separation between modules (e.g., Auth, Users, Orders)

Creating a Mock Collection from an Existing Collection

To avoid re-work, you can clone an existing live collection into a mock collection.

Steps:

  1. Click '...' more options against a particular live collection.

  2. Select Create Mock Collection.

    MockServer

  3. The structure and endpoints will be cloned into a new mock setup.

You can now start modifying responses and conditions to simulate various scenarios.

Executing and Monitoring Requests

Sending Requests to a Mock Collection

Once a collection is active:

  • Open any request inside it.
  • Click Send to preview the mock response.
  • You will receive a response based on how the request matches the conditions configured.

If the collection is inactive:

  • Sparrow will warn you.
  • No response will be returned until it’s re-activated.

History Logs

Sparrow logs every request made to an active mock server. These logs contain:

  • Timestamp of the request
  • Request method and path
  • Request headers and body
  • The matched mock response
  • Status code and returned payload

Use these logs to:

  • Debug incorrect conditions

  • Confirm request/response matches

  • Share behavior with team members

    MockServer

Contextual Actions

Each mock collection offers context menu options:

  • Rename collection
  • Add new mock request or folder
  • Start/stop mock server
  • Delete collection

These are available via the ... icon or right-click.

Sparrow’s Mock Server is designed to make API simulation as seamless and powerful as possible. Whether you're a frontend developer working independently of backend timelines or a QA engineer designing regression scenarios, the Mock Server saves time and brings confidence into your workflow.

You can start with a simple collection and gradually build towards dynamic mocks with conditional responses and full test coverage.