frontend-coding-standards
frontend-coding-standards copied to clipboard
Handling HTTP requests
What should the standard be for handling HTTP requests in your project?
There are multiple options:
Axios
Pros
- Already being used in current projects
- Compatible with older browsers like IE
Cons
- Uses XHR, a quite outdated technique to handle HTTP requests
Size: 13.4kB minified (https://bundlephobia.com/[email protected])
Fetch
Pros
- Native to modern browsers, so no external package required
Cons
- Needs a polyfill to work in old browsers like IE (https://caniuse.com/fetch)
Size: native
Redaxios
Pros
- Uses the API of Axios but uses Fetch under the hood
- Easy to upgrade from Axios
- Way smaller package size then Axios
Cons
- Needs a polyfill to work in old browsers like IE (https://caniuse.com/fetch)
Size: 1.9kB minified (https://bundlephobia.com/[email protected])
redaxios also implements the AbortController, so we will finally be able to cancel our requests. This will be especially useful in React, where we could cancel pending requests, whenever the component unmounts.