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 –...