Published Apr 13, 2025 ⦁ 8 min read
Local API Mocking: A Step-by-Step Guide for Developers

Nearly 90% of developers rely on APIs, and local API mocking can save time, cut costs, and improve testing. It lets you simulate API responses without live backend systems, enabling faster development and debugging. Here's why it matters:

  • Types of Mocking: Static (fixed responses), Dynamic (input-based), Proxy (record/replay).
  • Key Benefits: Improved security, parallel workflows, unlimited testing, and consistent debugging.
  • Tool Spotlight: ReqRes for macOS captures HTTP(S) traffic system-wide and lets you mock responses with Map Local and override rules, with no proxy settings to configure. A license is a one-time purchase of $60 USD per person.

Quick Setup for ReqRes: Download, approve the network extension, trust the ReqRes certificate for HTTPS, then add a rule for the endpoint you want to mock. Trigger the request from your app to confirm it fires.

Mocking helps frontend teams build UIs without backend dependencies and lets backend teams validate services in isolation. It’s also useful for load testing by simulating latency, high traffic, or errors.

Mocking Scenarios:

  • Frontend: Test UI responses for success, errors, and timeouts.
  • Backend: Validate service interactions, error handling, and data processing.
  • Load Testing: Simulate network conditions like high latency or random failures.

ReqRes also lets you inspect every request and response in real time, hold a request at a breakpoint, and hand captured traffic to an AI agent over MCP, making it useful for both small and large projects.

Tip: Keep mock configurations in version control and align them with production APIs for accurate testing.

Local API mocking is a game-changer for developers, enabling faster, safer, and more efficient workflows.

Setting Up ReqRes for API Mocking

ReqRes

System Requirements

ReqRes is a native SwiftUI app (notarized, sandboxed, no Electron), so it stays lightweight. Ensure your system meets these requirements:

  • macOS 14.6 or later
  • Permission to approve the ReqRes network extension in System Settings
  • For HTTPS inspection, trust in the ReqRes root certificate (the app walks you through installing it)

Installation Steps

Here’s how to get started:

  1. Download and Install

    Head over to reqresapp.com and download the latest version. The free version has every feature, with limits of 2 host filters, 1 rule and 10 HTTPS inspections per launch. ReqRes Pro lifts them for a one-time payment of $60 USD per person, excluding tax, with every 1.x update included (see the pricing page). Once downloaded, open the .dmg file and drag the ReqRes app into your Applications folder.

  2. Approve the Network Extension

    Click the capture button in the toolbar and macOS will ask to install the ReqRes network extension. Go to System Settings > General > Login Items & Extensions (on macOS 14 Sonoma, Privacy & Security > Extensions), click the ⓘ button next to Network Extensions, and switch ReqRes on. Choose Allow when macOS asks to add a VPN configuration; that is how traffic is routed through the extension, and no real VPN or third-party server is involved.

  3. Trust the Certificate

    HTTP traffic appears as soon as capture is running. For HTTPS, open Settings > Certificate in ReqRes, click Install CA Certificate, then Trust. Until the certificate is trusted, HTTPS requests still show up but without a readable body. There are no proxy settings to configure, and no proxy setting is left behind when you quit.

Verifying Mock API Setup

Add the host you want to mock (for example api.example.com) as a host filter in the sidebar, then create a rule under it for a path like /api/users. Use Map Local to answer with a JSON file on disk, or an override to return the status code, headers and body you choose. Then trigger the request from your app or a browser.

If everything is configured correctly, your app receives the mock response, complete with the HTTP status code and headers you set. Select the request in ReqRes to inspect it and confirm the request-response cycle.

For best results, keep detailed documentation of your mock API configurations. Include endpoint paths, request methods, and expected responses. This helps maintain consistency across your team and makes troubleshooting easier. With these steps, you’re ready to dive into various API mocking scenarios.

Common API Mocking Scenarios

With ReqRes set up, you can simplify both frontend and backend testing by simulating real API behavior in various situations.

Frontend Development Tasks

Frontend teams can build and test user interfaces quickly, even when the backend isn't ready, by using simulated API responses.

Response Type Mock Configuration Testing Scenario
Success (200) Valid user data Display user profile
Error (404) Empty response Show "User not found" message
Error (500) Server error message Test error handling
Slow response Hold the request at a breakpoint Validate loading indicators

For example, you can mock responses for login attempts, password resets, account verification, or session timeouts. This helps ensure the UI responds correctly in various situations.

Backend Testing Methods

Mock APIs are just as useful for backend testing, offering a controlled environment to isolate and validate specific components without relying on live services.

This approach allows you to:

  • Simulate interactions between services
  • Test how errors are handled
  • Verify data transformation processes
  • Check authentication mechanisms

For larger systems, you can maintain separate mock configurations for different scenarios. This ensures you can thoroughly test business logic without needing external dependencies.

Load Testing Options

Using mock APIs for load testing helps you evaluate how your application performs under different conditions. This is a job for a dedicated mock server or load-testing tool, which you can configure to simulate various network scenarios:

Test Scenario Configuration Purpose
High Latency 500ms delay Test timeout handling
Bandwidth Limit 1 Mbps cap Verify data streaming behavior
Request Volume 1000 requests/second Assess performance under load
Random Failures 5% error rate Test system resilience

Start with basic responses, then introduce delays, errors, or high request volumes to mimic real-world conditions. Keep an eye on system resources during these tests to ensure your mock API server remains stable.

Mock APIs provide a cost-effective, controlled environment, making them an excellent tool for startups and development teams alike.

ReqRes Advanced Features

Mocking with Rules

ReqRes mocks at the network layer: a rule matches requests to one of your host filters and changes what happens to them, so the real app sees the mock rather than a test harness. There are three kinds:

Rule What It Does Example
Map Local Answers the request with a file on disk Serve users.json for /api/users, or work offline
Override Replaces the response's status code, headers or body Make /orders return a 500 without taking your backend down
Extend Adds or changes headers on the real request Tag every request with X-Debug-Session: local

Here’s the kind of file a Map Local rule can serve for GET /api/users:

{
  "users": [
    { "id": 1, "name": "Ada Lovelace", "email": "[email protected]" },
    { "id": 2, "name": "Alan Turing", "email": "[email protected]" }
  ]
}

Once a rule is in place, you can confirm it fires by watching live traffic and checking that the response your app received is the one you defined.

Holding a Request with a Breakpoint

A rule applies every time it matches. A breakpoint, armed in Settings > Breakpoints, stops the next matching request before it reaches the server and waits for you. That makes it a simple way to see your loading states, and to decide per request whether to send it on, change it, or fail it with a status code of your choosing.

Traffic Monitoring and Control

ReqRes captures HTTP(S) traffic system-wide in real time through a macOS Network Extension, covering apps, browsers and background processes (command-line tools that ignore the system proxy, such as node scripts and Go programs, need an HTTPS_PROXY environment variable). You can inspect the method, URL, status, headers and body of every exchange, making it easier to confirm that your mocks are working without needing live servers. Host filters keep the list scoped to the services you care about, and the search bar accepts free text or host:, method:, status: and path: tokens.

Mocking from Captured Traffic with an AI Agent

ReqRes ships an MCP server, so Claude Code, Claude Desktop, Cursor or any MCP client can read the traffic it captured, diff two requests, wait for the request you are about to trigger, export a HAR, or turn a captured response into a mock. Credential-shaped values are redacted before anything leaves the app, every change asks for your approval, and the whole bridge has an off switch.

Team Usage Guidelines

Here are some tips for using ReqRes effectively as a team:

  • Configuration Management: Keep the files your Map Local rules serve in version control, next to the code that consumes them.
  • Update Coordination: Ensure everyone is working with the same mock data to avoid discrepancies.

For a team, buy 1 license per person: each license covers up to 2 Macs, volume discounts start at 5 licenses, and every 1.x update is included with nothing to renew. See the pricing page.

API Mocking Guidelines

Matching Production APIs

Clearly define production endpoints, error codes, headers, and latency early in the process - ideally during the design phase. This helps validate assumptions before development kicks off.

Aspect Implementation Strategy Validation Method
Response Format Replicate the exact JSON/XML structure Automated schema validation
Status Codes Cover all possible production error states Edge case testing
Headers Include authentication tokens Security verification
Latency Mimic realistic response times Performance monitoring

Once you’ve aligned your mock APIs with production, manage your mock data carefully to ensure it stays consistent and accurate.

Mock Data Management

  • Save mock configurations in your version control system.
  • Provide thorough documentation for mock scenarios and their expected behaviors.
  • Use dynamic responses based on input parameters to handle variability.
  • Implement stateful mocking for workflows that require multiple steps.

These steps help ensure your mock data remains reliable as your APIs grow and change.

Maintaining Mock Accuracy

To keep your mocks aligned with production APIs, follow these practices and routinely validate them as changes are made:

1. Contract Testing Integration
Validate service interactions to ensure they comply with your API specifications.

2. CI/CD Pipeline Integration
Automate mock response checks with every code update to catch discrepancies early.

3. Documentation Updates
Keep detailed records of mock configurations, scenarios, and any known limitations to avoid confusion.

For more complex workflows, use realistic test data to better simulate production scenarios:

Scenario Type Mock Implementation Validation Method
High Load Simulate multiple concurrent requests Load testing tools
Error States Create specific error responses Error handling verification
Edge Cases Test boundary conditions Integration testing
Security Mock authentication and authorization flows Security testing suite

Conclusion

Summary

API mocking plays a crucial role in modern development, with nearly 90% of developers relying on APIs [1]. By using local API mocking, teams can work independently of live servers, speeding up workflows and cutting costs tied to third-party APIs [1].

Benefit Impact
Development Speed Enables parallel workflows
Cost Efficiency Avoids third-party API expenses
Testing Reliability Provides a stable, controlled setup
Security Lowers the risk of data breaches

ReqRes Benefits

ReqRes brings local API mocking to the app you are actually building. It is a native macOS web-debugging proxy that captures HTTP(S) traffic system-wide through a Network Extension, so there are no proxy settings to configure and no system proxy left behind when you quit.

Key features of ReqRes for local API mocking include:

  • Map Local: Serve a file from disk in place of a real response, for mock data or offline work.
  • Response overrides: Set the status code, headers and body to test error paths your backend won't produce on demand.
  • Request header rules: Add or change headers on outgoing requests.
  • Breakpoints: Stop the next matching request and decide what your app sees.
  • MCP server: Let an AI agent read captured traffic and turn a captured response into a mock, with credentials redacted and every change approved by you.

With its straightforward setup and native design, ReqRes simplifies rapid prototyping and streamlines development workflows. Its app shell is open source (FSL-1.1-ALv2), so you can read how the tool that handles your traffic works.

Related posts