frontend-coding-standards icon indicating copy to clipboard operation
frontend-coding-standards copied to clipboard

Handling HTTP requests

Open MickJasker opened this issue 5 years ago • 1 comments

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

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

Size: 1.9kB minified (https://bundlephobia.com/[email protected])

MickJasker avatar Sep 11 '20 12:09 MickJasker

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.

psimk avatar Sep 11 '20 12:09 psimk