Skip to main content
Terminal showing APXY mock rule returning a 200 response
Tutorial

How to Mock a REST API in 5 Minutes with APXY

Create a fully functional mock REST API in under five minutes. No code, no config files, no server to maintain. One command to install, one command to add a rule.

APXY Team5 min read

Most mock API setups start with a config file, a YAML schema, or a dependency to install. This tutorial skips all of that. You will have a working mock REST API returning real JSON in about five minutes.

What you need

  • macOS or Linux
  • A terminal

That is it. No Node.js version pinning. No Docker. No project scaffolding.

Step 1: Install APXY

curl -fsSL https://apxy.dev/install.sh | bash

Verify it worked:

apxy --version

Step 2: Start the proxy

apxy start --port 8080

APXY starts a local HTTPS proxy that intercepts traffic. The Web UI opens at http://localhost:8081 so you can see rules and captured requests in real time.

Step 3: Add your first mock rule

This is the core step. Tell APXY which URL to intercept and what to return:

apxy rules add \
  --match "GET /api/users" \
  --status 200 \
  --body '[{"id":1,"name":"Alice"},{"id":2,"name":"Bob"}]' \
  --header "Content-Type: application/json"

Now any GET request to /api/users going through APXY will return that JSON with a 200 status.

Step 4: Test it

Route a request through the proxy and hit your mock:

curl -x http://localhost:8080 http://localhost:3000/api/users

Or route your whole app:

HTTP_PROXY=http://localhost:8080 HTTPS_PROXY=http://localhost:8080 npm run dev

Any request from your app to /api/users now gets the mocked response—no backend required.

Common mock patterns

Mock a 404 for a missing resource

apxy rules add \
  --match "GET /api/users/999" \
  --status 404 \
  --body '{"error":"User not found"}' \
  --header "Content-Type: application/json"

Mock a POST that creates a resource

apxy rules add \
  --match "POST /api/users" \
  --status 201 \
  --body '{"id":3,"name":"Carol","created":true}' \
  --header "Content-Type: application/json"

Simulate a server error

apxy rules add \
  --match "GET /api/products" \
  --status 500 \
  --body '{"error":"Internal Server Error"}'

Add a response delay

apxy rules add \
  --match "GET /api/slow-endpoint" \
  --status 200 \
  --body '{"result":"ok"}' \
  --delay 2000

The --delay flag adds a 2-second pause before the response. Useful for testing loading states and timeout handling.

Use the Web UI instead of the CLI

If you prefer clicking to typing, open http://localhost:8081, go to the Rules tab, and click Add Rule. Fill in the URL pattern, status code, headers, and body in the form. The rule activates immediately.

Use a pre-built template

For common APIs like Stripe, GitHub, and OpenAI, APXY ships with ready-made rule sets so you do not have to write every response yourself:

curl -fsSL https://raw.githubusercontent.com/apxydev/apxy/main/mock-templates/openai/rules.json \
  -o openai-rules.json
apxy rules import openai-rules.json

Browse all available templates at apxy.dev/templates.

What to do next

Once you have a few mock rules running, the natural next step is to capture real traffic and convert it to a mock. That is the Record & Replay pattern: make a real API call through the proxy, see the live response in the traffic log, then save it as a rule. Your mock immediately reflects real API behavior.

See How to Debug a Failing API Call with APXY for the full capture-inspect-replay workflow.

tutorialapi-mockingrest-apigetting-started

Debug your APIs with APXY

Capture, inspect, mock, and replay HTTP/HTTPS traffic. Free to install.

Install Free

Related articles

Stop guessing, start shipping

Debug and mock every API call in one local tool

APXY Pro unlocks the full network debugging loop for you and your AI coding agents. Install free in seconds, upgrade once when it earns its keep.

  • Unlimited traffic history & mock rules
  • API diagnosis, scripts, breakpoints
  • One-time $79 — lifetime updates, no subscription
$79one-time

Lifetime updates. 14-day refund. No account required to start.

Buy Pro — $79Install Free