Skip to content

Instantly share code, notes, and snippets.

@jsjoeio
Last active May 23, 2023 14:54
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jsjoeio/0fd8563bc23ef852bc921836512992d9 to your computer and use it in GitHub Desktop.
Save jsjoeio/0fd8563bc23ef852bc921836512992d9 to your computer and use it in GitHub Desktop.
axios vs. isomorphic-fetch

Which library should you use for making HTTP requests from a React/Node project?

In this doc, we'll explore two popular libraries: axios and isomorphic-fetch.

axios

Quick facts:

  • 37,439 stars on GitHub
  • 130 contributors
  • most recent commit: March 8th, 2018
  • created in Aug. 2014

Features (taken from axios):

  • Make XMLHttpRequests from the browser
  • Make http requests from node.js
  • Supports the Promise API
  • Intercept request and response
  • Transform request and response data
  • Cancel requests
  • Automatic transforms for JSON data
  • Client side support for protecting against XSRF

Pros

Cons

isomorphic-fetch

Quick facts:

  • 5,385 stars on GitHub
  • 9 contributors
  • most recent commit: May 22nd, 2016
  • created in Nov. 2014

Pros

  • more downloads per month

Cons

  • library is considered a polyfill.
  • This adds fetch as a global so that its API is consistent between client and server.
Sources
@awhit012
Copy link

Importantly, Axios is 4.3 KB while isomorphic-fetch is 2.7KB. Another library, isomorphic-unfetch is a mere 582B, and does everything I want it to. That's my pick fwiw :)

@diegomarcelino92
Copy link

@awhit012 como fazer um timeout no isomorphic?

@ricardocanelas
Copy link

@diegomarcelino92

const controller = new AbortController();
const promise = fetch('/api/products', { 
   // ... 
   signal: controller.signal,
);

const timeoutId = setTimeout(() => controller.abort(), 4000);

@sanamumtaz
Copy link

Hi, my question is related to isomorphic-unfetch. Does AbortController work with isomorphic-unfetch when it's used as a ponyfill?

@xero-lib
Copy link

xero-lib commented Jan 21, 2021

Hi, my question is related to isomorphic-unfetch. Does AbortController work with isomorphic-unfetch when it's used as a ponyfill?

what is a ponyfill

@Prajwal-Kamboj
Copy link

Hi, my question is related to isomorphic-unfetch. Does AbortController work with isomorphic-unfetch when it's used as a ponyfill?

what is a ponyfill

Polyfill

@andreyshedko
Copy link

Hi, my question is related to isomorphic-unfetch. Does AbortController work with isomorphic-unfetch when it's used as a ponyfill?

what is a ponyfill

It's for the horses pretending to be a pony.

@borankux
Copy link

Hi, my question is related to isomorphic-unfetch. Does AbortController work with isomorphic-unfetch when it's used as a ponyfill?

what is a ponyfill

It's for the horses pretending to be a pony.
😆

@hpelitebook745G2
Copy link

hpelitebook745G2 commented May 23, 2023

maybe he meant this ponyfill? coincidentally, which was mentioned here.

@sanamumtaz
Copy link

Yes. It's mentioned in the package's usage. It's a pretty straightforward concept. Regarding my question, it doesn't hold now since we moved to another library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment