Skip to content

Latest commit

 

History

History
11 lines (6 loc) · 1.04 KB

api-mock-server.md

File metadata and controls

11 lines (6 loc) · 1.04 KB

API Mock Server

For prototyping the API use mswjs, which is a great tool for quickly creating frontends without worrying about servers. It is not an actual backend, but a mocked server inside a service worker that intercepts all HTTP requests and returns desired responses based on the handlers you define. This is especially useful if you only have access to the frontend and are blocked by some not implemented features on the backend. This way, you will not be forced to wait for the feature to be completed or hardcode response data in the code, but use actual HTTP calls to build frontend features.

It can be used for designing API endpoints. The business logic of the mocked API can be created in its handlers.

API Handlers Example Code

Data Models Example Code

Having fully functional mocked API server also handy when it comes to testing, you don't have to mock fetch, but make requests to the mocked server instead with the data your application would expect.