In the next steps, we will change the Fetch API used in the HTTP wrapper for the axios library. Follow these steps to change it correctly:
- Install axios in your packages. You need to open Terminal (macOS or Linux) or Command Prompt/PowerShell (Windows) and execute the following command:
> npm install --save axios
The version used in this recipe was 0.19.0. Watch for changes to axios, as there is no LTS version of the library yet.
- Open the baseFetch.js file inside the src/http folder.
- Simplify the method so that it will receive three arguments, url, method, and options, and return an axios method, calling the HTTP request with the methods passed as the constructor of the instance:
import axios from 'axios';
export default async (url, method, options = {}) => axios({
method: method.toUpperCase(),
url,
...options,
});