Mocking the API
In the previous chapter, we built the application pages that use test data. The UI of the pages is complete, but the pages are not functional yet. We are using the test data without making requests to the API.
In this chapter, we will learn what mocking is and why it is useful. We will learn how to mock the API endpoints with the msw
library, a great tool that allows us to create mocked API endpoints that behave as real-world API endpoints.
We will also learn how to model the data of our application entities with the @
mswjs/data
library.
In this chapter, we will cover the following topics:
- Why is mocking useful?
- Introduction to MSW
- Configuring data models
- Configuring request handlers for API endpoints
By the end of this chapter, we will learn how to generate fully featured mocked APIs with data models set in place, which will make our code base less dependent on external APIs during development.