Back to all posts
Using Local Proxies for API Testing: A Developer's Guide to Intercepting and Debugging HTTP Requests

Using Local Proxies for API Testing: A Developer's Guide to Intercepting and Debugging HTTP Requests

August 22, 2026

Introduction

When developing modern applications, APIs are the backbone of communication between services. However, testing and debugging API interactions can be challenging. Local proxies act as a middleman, allowing developers to inspect, modify, and debug HTTP requests and responses in real time. This guide explores how to configure and use local proxies for API testing, focusing on tools like mitmproxy and Charles Proxy, and their practical applications in development workflows.

Why Use Local Proxies for API Testing?

Local proxies offer several advantages:

  • Intercept Traffic: View all HTTP/HTTPS requests and responses between your application and the server.
  • Modify Requests/Responses: Simulate edge cases by altering headers, payloads, or status codes.
  • Debug Issues: Identify problems like incorrect headers, malformed payloads, or unexpected server behavior.
  • Test Security: Verify SSL/TLS configurations and detect potential vulnerabilities.

Choosing the Right Proxy Type

For local development, forward proxies are ideal because they:

  • Operate on your local machine
  • Require minimal setup
  • Support HTTP/HTTPS protocols
  • Provide real-time traffic inspection

Avoid using external proxy services for local testing, as they introduce latency and security risks. Instead, leverage tools designed for local use.

Setting Up a Local Proxy

Step 1: Install a Proxy Tool

Choose one of these popular options:

  • mitmproxy (Open-source, CLI-based):
    pip install mitmproxy
    
  • Charles Proxy (GUI-based, commercial): Download from charlesproxy.com
  • Fiddler (Windows-focused, free): Download from telerik.com/fiddler

Step 2: Start the Proxy Server

For mitmproxy:

mitmproxy --listen-port 8080

This starts a proxy server on port 8080. Note the generated CA certificate path (usually in ~/.mitmproxy/).

Step 3: Configure Your Application

For cURL:

curl -x http://localhost:8080 -U mitmproxy:mitmproxy https://api.example.com/data

For Python:

import requests
proxies = {
    "http": "http://localhost:8080",
    "https": "http://localhost:8080"
}
response = requests.get("https://api.example.com/data", proxies=proxies)

For Node.js:

const axios = require('axios');
axios.get('https://api.example.com/data', {
    proxy: {
        host: 'localhost',
        port: 8080
    }
});

Intercepting and Debugging Requests

Using mitmproxy

  1. Start mitmweb for a web interface:
mitmweb --listen-port 8080

Open http://localhost:8081 in your browser.

  1. Capture Traffic: All requests will appear in the dashboard.

  2. Modify Requests: Click a request, then edit headers or body:

# Example: Add a custom header
headers = {"X-Custom-Header": "test-value"}
  1. Replay Requests: Right-click a request to replay it with modifications.

Using Charles Proxy

  1. Enable Transparent HTTP Proxying: Go to Proxy > Settings > Transparent HTTP Proxy and set the port to 8080.

  2. Map Local Sources: Simulate API responses by mapping remote URLs to local files:

    <!-- Charles Map Remote feature -->
    <map-remote>
        <from>https://api.example.com/data</from>
        <to>/Users/username/local-data.json</to>
    </map-remote>
    

Common Use Cases

1. Testing CORS Issues

  • Problem: Browser blocks cross-origin requests.
  • Solution: Use the proxy to inspect Access-Control-Allow-Origin headers in responses.

2. Simulating API Latency

  • Problem: Unreliable network conditions.
  • Solution: In Charles, use Throttle > Simulate Speed to add latency.

3. Modifying API Responses

  • Problem: Need to test error handling.
  • Solution: In mitmproxy, use a script to alter responses:
    def response(flow):
        if "api.example.com/data" in flow.request.pretty_url:
            flow.response.status_code = 500
            flow.response.content = b"{\"error\": \"Internal Server Error\"}"
    

4. Validating HTTPS Certificates

  • Problem: SSL certificate validation errors.
  • Solution: Install the proxy’s CA certificate in your system/browser to bypass warnings.

Security Considerations

  • Install CA Certificates: For HTTPS interception, install the proxy’s root CA certificate in your development environment.
  • Never Use in Production: Local proxies are insecure and should only be used in controlled environments.
  • Disable Proxy When Idle: Shut down the proxy when not in use to prevent accidental traffic interception.

Integrating with RoProxy (Optional)

While local proxies are ideal for development, RoProxy offers secure, scalable residential IPs for production testing. For example:

  • Use local proxies for debugging API calls.
  • Switch to RoProxy’s residential IPs when simulating real-world traffic.

Conclusion

Local proxies are indispensable tools for API testing, offering granular control over HTTP traffic. By following these steps, developers can streamline debugging, simulate edge cases, and improve application reliability. Whether using mitmproxy’s scripting capabilities or Charles’s intuitive interface, local proxies empower developers to build better APIs and applications.

Start with a simple setup today, and unlock new possibilities in your development workflow!