Reader small image

You're reading from  Enterprise React Development with UmiJS

Product typeBook
Published inMay 2022
Reading LevelIntermediate
PublisherPackt
ISBN-139781803238968
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Douglas Alves Venancio
Douglas Alves Venancio
author image
Douglas Alves Venancio

Douglas has a background in systems analysis and development, his passion is to help customers and the community solve problems. Over the past few years, he has mainly worked with digital products and innovation, delivering the best user experience with modern web applications.
Read more about Douglas Alves Venancio

Right arrow

Simulating data and API responses

In this section, you'll learn how to create mock files to simulate backend logic and API responses.

Mock files are helpful to decouple frontend development from backend development, as you don't need the backend ready to make requests and populate your interface with data.

A mock file is simply a JavaScript object with endpoint route definitions and a response to each endpoint. Consider the following example:

export default {
  'GET /api/products': { total: 0, products: [] },
};

In this example, when the project is running, we can send an HTTP GET request to http://localhost:8000/api/products to receive the object defined in the mock file.

Umi will registry all files with the .js and .ts extensions inside the mock folder as mock files.

Now that we know how mock files work, let's create mock files for our application. Follow these steps:

  1. In the project root directory, create a new folder...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Enterprise React Development with UmiJS
Published in: May 2022Publisher: PacktISBN-13: 9781803238968

Author (1)

author image
Douglas Alves Venancio

Douglas has a background in systems analysis and development, his passion is to help customers and the community solve problems. Over the past few years, he has mainly worked with digital products and innovation, delivering the best user experience with modern web applications.
Read more about Douglas Alves Venancio