Prompt

How do I mock a downstream API for local development?

Technology / Testing & QA1 observationLast seen Oct 6, 2026

Latest observation

Oct 6, 2026OpenAI APIWeb search: off

A good way to mock a downstream API for local development depends on how much realism you need and what stack you’re using. Common options:

1) Run a local mock server

Create a small HTTP server that returns canned responses matching the real API.

Good for: fast local dev, reproducible responses
Tools: JSON Server, WireMock, Mockoon, Prism, json-server, Express/FastAPI/Flask, etc.

Example (Node/Express):

import express from "express";

const app = express();

app.get("/users/:id", (req, res) => {
  res.json({ id: req.params.id, name: "Mock User" });
});

app.listen(3001, () => console.log("Mock API on http://localhost:3001"));

Then point your app’s base URL to http://localhost:3001.


2) Use service virtualization tools

These are designed for HTTP mocks, contract testing, and replaying recorded traffic.

  • WireMock: very common for REST APIs
  • Mockoon: easy GUI-based mock server
  • Prism: can mock from OpenAPI specs
  • Stoplight: API design + mocking

Good for: teams, complex APIs, OpenAPI-driven workflows


3) Mock at the client layer

If your app calls the downstream API through a wrapper/client, mock that client in tests or dev builds.

Good for: unit/integration tests, keeping local app startup simple
Example approach: replace the API client implementation with a fake one behind an interface.


4) Proxy and record/replay

Run a proxy that records real API responses and replays them later.

Good for: realistic responses, less manual setup
Caution: keep secrets out, and be careful with stale/production-specific data.


5) Use a dev/staging environment

If allowed, point local dev to a sandbox/staging API.

Good for: real behavior without building mocks
Tradeoff: external dependency, slower, may be unstable or rate-limited.


Recommended approach

For most local development, use:

  • Mock server with canned responses for simplicity
  • OpenAPI-based mocking if you already have an API spec
  • Client abstraction so you can switch between real and mock via config

Practical setup pattern

  1. Put the downstream base URL in config:
    • DOWNSTREAM_API_BASE_URL=http://localhost:3001
  2. Run a mock server locally
  3. Add sample fixtures for common responses
  4. Optionally add error cases:
    • 404, 500, timeouts, malformed payloads
  5. Use environment variables or a feature flag to switch between real and mocked APIs

Example config switch

# real API
DOWNSTREAM_API_BASE_URL=https://api.example.com

# local mock
DOWNSTREAM_API_BASE_URL=http://localhost:3001

If you tell me your language/framework and whether you have an OpenAPI spec, I can suggest the best tool and show a concrete setup.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.