Mock Service Worker (MSW)

Mock Service Worker (MSW) is an API mocking library for JavaScript. It intercepts requests at the network level, through a Service Worker in the browser and through interceptors in Node.js, and answers them with handlers you define.

Because the application keeps making real HTTP requests, the same mocks serve local development, tests and demos without changes to application code. Combined with an agreed OpenAPI contract and generated test data, for example from Faker, frontend work can start before the backend endpoint exists.

Updates

Trial

On a Vue.js counselling platform that we have reused for a second client, MSW mocks the entire backend API, and local development runs against the mocks by default, with a switch to the real API. This keeps frontend work independent of backend development cycles: new features start with types, mocks and routes against the agreed API contract.