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

Sending HTTP requests with Umi request

In this section, we'll develop the requests to the backend using the umi-request library.

We'll create all the requests in separate files inside the services folder for each context. This organization helps us clean the components' code and reuses the requests over the interfaces.

For sending HTTP requests, we'll use Umi request. This is a library based in the fetch and axios libraries that is simple to use and provides common features such as error handling and caching. Consider the following example:

request<Product>('/api/products', {
  method: 'POST',
  headers: { Authorization: 'Bearer eyJhbGciOi...' },
  params: { onSale: true },
  data: {
    id: 0,
    title: 'My product',
    price: 10.0,
  },
});

The request function requires two main parameters –...

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