Mockfly vs MSW: a hosted mock server or in-process interception?

Mock Service Worker (MSW) and Mockfly solve the same problem, an API that is not there yet, from opposite ends. MSW intercepts requests inside your JavaScript. Mockfly answers them from a URL on the internet. Most frontend teams end up wanting both; this page explains which one to reach for and when.

What MSW is

MSW is an open-source library that intercepts HTTP requests at the network level of your own process: a Service Worker in the browser, request interceptors in Node. You describe handlers in code, next to your tests or your app, and the request never leaves the machine. It is framework-agnostic, works in Jest, Vitest, Playwright and Storybook, and the same handlers run in the browser during development.

Its strength is that the mock lives with the code: versioned, reviewed, typed if you want, and free of any network. Its limit is the same fact: the mock only exists where that code runs.

What a hosted mock server adds

  • One URL for everyone. The iOS app, the Android app, the backend service that calls the API, the QA engineer with Postman and the designer clicking through a prototype all hit the same mock.
  • No code to change a response. A product manager or a tester can flip an endpoint from 200 to 500, edit a body or add a rule in the UI. With MSW that is a pull request.
  • Realistic data without writing it. Faker.js templates re-evaluate on every request and the AI can generate a whole payload from a sentence. MSW can use Faker too, but you wire it yourself.
  • Import the contract. Drop in the OpenAPI spec or the Postman collection and every path is an endpoint. With MSW you write, or generate, a handler per route.
  • Logs and documentation. See every request the mock received, share auto-generated docs with the backend team, and proxy the endpoints that already exist to the real API.

Where MSW is simply better

  • Unit and component tests: no network, no flakiness, no rate limits.
  • Offline development on a plane, without the Mockfly CLI.
  • Type-safe handlers that fail the build when the API contract changes.
  • Anything where the mock must ship inside the repository and nowhere else.

Features comparison

FeatureMockflyMSW
Where the mock runsHosted URL (or the offline CLI on localhost)Inside your browser or Node process
Callable from mobile apps, other services and QA tools
Works inside Jest or Vitest with no network
Edit responses without a code change✅ Web UI
Conditional responses✅ Rules with 16 comparators and AND/OR groups✅ Any JavaScript in the handler
Realistic data✅ Faker.js templates and AIBring your own Faker
Import OpenAPI or PostmanVia third-party generators
Request logs and auto documentation
WebSocket mocking
PriceFree plan, Pro 15€/month, Team 49€/monthFree, open source

A sensible setup for a frontend team

  1. Agree the contract with the backend team as an OpenAPI spec.
  2. Import the spec into Mockfly. Point the app at the project URL through an environment variable so switching to the real API later is a one-line change.
  3. Generate MSW handlers from the same spec for unit tests, so both mocks describe the same API.
  4. When the backend ships an endpoint, switch that endpoint to proxy mode and leave the rest mocked.

Start with the free plan at app.mockfly.dev, or read how to mock API calls in React for working code with fetch, Axios and MSW.

Frequently asked questions

Is Mockfly a replacement for MSW?

Not in unit tests. MSW is the better tool for mocking inside a test runner, with no network hop. Mockfly replaces the ad-hoc mock servers, hardcoded fixtures and "ask the backend team" moments that MSW does not cover: a shared URL that mobile apps, QA, designers and CI can all call.

Can I use MSW and Mockfly together?

Yes, and many teams do. Point the app at a Mockfly project during development and in staging, and keep MSW handlers for component and integration tests. If you want the two to agree, generate your MSW fixtures from the same OpenAPI spec you import into Mockfly.

Does MSW work for mobile apps or for other services?

MSW runs where your JavaScript runs: a browser service worker or a Node process. A native iOS or Android app, a backend written in Go, or a QA engineer with Postman cannot use your handlers. A hosted mock server gives all of them one URL.

What does each one cost?

MSW is open source and free. Mockfly has a free plan (500 requests a day, 4 endpoints), Pro at 15€ a month with no limits, and Team at 49€ a month with 5 seats. You pay for the hosting and the UI, not for the mocking concept.