
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.
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 | bashVerify it worked:
apxy --versionStep 2: Start the proxy
apxy start --port 8080APXY 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/usersOr route your whole app:
HTTP_PROXY=http://localhost:8080 HTTPS_PROXY=http://localhost:8080 npm run devAny 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 2000The --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.jsonBrowse 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.
Debug your APIs with APXY
Capture, inspect, mock, and replay HTTP/HTTPS traffic. Free to install.
Install FreeRelated articles
What is API Mocking? A Developer's Guide
API mocking lets you simulate a real API without calling it. This guide explains what it is, why developers use it, when to mock vs when not to, and how to get started in under five minutes.
TutorialDynamic API Responses: Scripting with JavaScript in APXY
Static mock rules return the same response every time. When you need to inject dynamic data, modify responses conditionally, or simulate real API behavior like rate limiting, APXY's JavaScript scripting engine handles it.