At some point in every project, the frontend and backend drift apart like tectonic plates. One side is ready to build features; the other is still negotiating payload shapes, naming things, or bravely rewriting the same endpoint for the third time.

This is where frontend mocking steps in—not as a hack, but as a small act of professional self‑preservation.


Unchain the Frontend

Using axios together with axios-mock-adapter, you can completely decouple frontend development from backend availability.

Instead of waiting for real APIs, you:

  • Intercept HTTP requests
  • Return mock payloads
  • Simulate success and failure states
  • Keep shipping UI without blocking on anyone

No shade to backend colleagues—this just means everyone sleeps better.


Mocking Like You Mean It

Mocks shouldn’t just return happy-path data. That’s fantasy land.

With axios-mock-adapter you can:

  • Return realistic payloads
  • Sprinkle in HTTP status codes
  • Rehearse error states on demand
  • Test loading, empty, and failure scenarios deliberately

If your UI only works when everything goes perfectly, it doesn’t really work.


Environment Flags: Flip the Switch, Don’t Rewrite Code

Mocking should be opt-in, not duct-taped.

Wire it up with an environment flag and your npm scripts:

  • npm run dev → real APIs
  • npm run mock → mocked responses

This keeps production data sacred and avoids the “why is staging deleting real users?” incident that nobody wants to explain.

Your app boots the same way—only the data source changes.


Example Mock User Data

Keep your mock data:

  • Small
  • Predictable
  • Human-readable

You’re telling a story to the UI, not generating a census.

const mockUser = {
  id: "u_123",
  name: "Ada Lovelace",
  role: "Analytical Engine Whisperer",
};

Good mock data makes it obvious what matters and what doesn’t.


Why This Is a Big Deal

Frontend mocking lets you:

  • Build UI before APIs exist
  • Develop in parallel instead of in line
  • Explore edge cases safely
  • Move fast without lying to yourself

It also reduces pressure on backend changes being “perfect” the first time. Contracts can evolve without blocking progress.


Mocks Encourage Better Boundaries

A pleasant side effect: mocking forces you to think in contracts.

If your frontend explodes when an endpoint changes slightly, that’s a signal. Clear request/response boundaries make both sides calmer and more resilient.

Mocks are not lies—they’re rehearsals.


When to Turn Mocks Off

  • Integration testing
  • End-to-end testing
  • Anything involving real persistence or auth

Mocks are a development superpower, not a production crutch.


Final Thought

Mocking your APIs isn’t cutting corners—it’s removing unnecessary waiting.

While one teammate fine-tunes database indexes or debates naming conventions, you can:

  • Build screens
  • Polish interactions
  • Handle edge cases
  • Ship confidence

Flip the flag. Keep building. Let the plates drift peacefully.

Back to Philosophy