Mock the active endpoint
Keep local-proxy focused so everything else stays real.
I was building a frontend screen that had multiple UI states depending on backend data:
The problem wasn’t UI components — it was reproducing the exact backend responses at the exact moment during development.
So I used local-proxy for selective mocking: mock only the endpoint I’m actively working on, and forward the rest to the real backend.
You’ll set up a proxy that:
POST /v1/lines/balance) and returns different JSON based on your active_scenario.scenarios.json and refreshing your frontend (no redeploy).npm install -g @bvbmz/local-proxyscenarios.jsonFrom your project folder:
local-proxy --initThis creates scenarios.json.
local-proxy --target https://api.example.comBy default, local-proxy listens on:
http://localhost:5050/apiSo your frontend should use http://localhost:5050/api as its API base URL while developing.
Open scenarios.json and add a rule for the request you want to control.
Example (based on the story endpoint pattern):
{ "rules": [ { "method": "POST", "match": "/v1/lines/balance", "enabled": true, "active_scenario": "prepaid_no_bills", "scenarios": { "prepaid_no_bills": { "status": 200, "file": "fixtures/prepaid_no_bills.json" }, "prepaid_with_bills": { "status": 200, "file": "fixtures/prepaid_with_bills.json" }, "error500": { "status": 500, "json": { "message": "Internal Server Error" } } } } ]}Notes:
method + match must match the request your frontend is actually making.match is the path behind the proxy’s API prefix (you typically call /api/... in the browser, but match /v1/... in scenarios.json).To test a different UI state, change just:
active_scenarioFor example:
"active_scenario": "prepaid_with_bills" to see the “unpaid bills” UI"active_scenario": "error500" to see the error screenThen refresh your frontend.
If you want to test loading spinners or timeout handling, add delay to a scenario:
{ "status": 200, "delay": 3, "file": "fixtures/prepaid_no_bills.json"}Make the request your frontend normally makes, but point it at your proxy.
For example:
curl -X POST "http://localhost:5050/api/v1/lines/balance" \ -H "Content-Type: application/json" \ -d '{ "example": "payload" }'If your rule matches, you should get the status / json / file response from your active_scenario.
If you call an endpoint that requires auth, include the same headers/tokens your frontend uses.
method, match, and enabled: true.http://localhost:5050/api (or set --api-prefix to match whatever your app calls).scenarios.json, then refresh/retry the request (the proxy reads the latest config each request in this workflow).When you’re developing, add rules only for the few endpoints you’re actively changing.
Mock the active endpoint
Keep local-proxy focused so everything else stays real.
Edit JSON, refresh UI
Scenario switching should be a config edit, not a rebuild.
Use fixtures for realism
Put bigger payloads in fixtures/ and reference them from scenarios.json.