If you're building frontend applications, you've probably encountered API mocking at some point.
Two common approaches are:
Local mocking with Mock Service Worker (MSW)
Hosted mock APIs
While both help developers continue working without a real backend, they solve very different problems.
MSW (Mock Service Worker) intercepts network requests and returns mocked responses directly in the browser or Node.js.
Advantages:
Excellent for local development
Great for unit and integration tests
No external infrastructure required
Works well with React, Vue, Angular, and other frontend frameworks
MSW is often the best choice when a single developer wants fast, isolated testing.
Hosted mock APIs provide publicly accessible endpoints that return predefined responses.
Instead of intercepting requests locally, applications call real HTTPS endpoints hosted in the cloud.
Advantages:
Shareable across teams
Accessible from QA environments
Useful for webhook testing
Can be used in CI/CD pipelines
No local setup required for consumers
MSW is ideal when:
Testing frontend components
Running automated tests
Working entirely on your local machine
Mocking APIs during development
Example:
A React developer wants to test loading states and error handling without touching a backend.
MSW is probably the best solution.
Hosted mocks become useful when:
Frontend and QA teams need the same endpoint
Product managers need demo environments
Third-party systems need callback URLs
Multiple teams need a shared contract
Example:
A payment provider needs a webhook URL.
A local mock cannot receive requests from external systems.
A hosted endpoint can.
Interestingly, creating mocks is rarely the hardest part.
The harder challenge is keeping mocks aligned with reality.
Over time:
APIs change
Fields are removed
Types evolve
Response structures drift
Mocks continue to pass while production behavior changes underneath them.
This is where contract validation and drift detection become important.
Use MSW when:
You need local-first development
You are testing frontend behavior
You want fast feedback loops
Use hosted mock APIs when:
Multiple people need the same mock
You need public URLs
You are testing integrations or webhooks
You need environment sharing
In many teams, the answer isn't MSW or hosted mocks.
It's both.
MSW for local development.
Hosted mocks for collaboration, integrations, and shared environments.
MSW remains one of the best local mocking tools available.
Hosted mock APIs solve a different class of problems centered around collaboration and integration workflows.
The right choice depends on where the bottleneck exists in your development process.
0
0
0