mikeal / r2

HTTP client. Spiritual successor to request.
Apache License 2.0
4.45k stars 117 forks source link

What does this library solve that fetch does not? #9

Open PaulBGD opened 7 years ago

st-schneider commented 7 years ago

And what would be the benefits over libs like axios?

tuananh commented 7 years ago

my guess is that same api between node and browser?

ruanyl commented 7 years ago

my guess is that same api between node and browser?

But fetch has its own specification: https://fetch.spec.whatwg.org/ Maybe I didn't get the key point, but isn't this repo just a wrap of fetch?

ljharb commented 7 years ago

The purpose of fetch is to be a low level primitive that libraries wrap; it's not really meant to be used directly.

dandv commented 7 years ago

How does this library compare with @bitinn's node-fetch ?

batjko commented 7 years ago

As far as I can see, it adds only two things over fetch:

  1. It automatically uses a polyfill if used in node (via node-fetch), and
  2. it lowercases headers for you.

And the rest is largely just recreating fetch's API. Granted, this could be done easily manually, but as a simple and small wrapper, this one will do the job quickly.

abenhamdine commented 7 years ago

FWIW, one could also be interested in checking wretch https://github.com/elbywan/wretch which is also a tiny wrapper around fetch.

mikemaccana commented 7 years ago

Lots of thumbs down but @ljharb 's comment is accurate: Fetch's author specifically states he designed it as a low level HTTP/S client. Hence fetch doesn't use content types, encode query strings, etc.

Personally I'd like to see a high level API with those things built on top of fetch.

gr2m commented 6 years ago

As this seems to be a common question, it would be nice to address it in the README

DevBrent commented 6 years ago

The primary reasons I like r2 are that it is a very small nearly transparent library and you do not have to do two awaits to get the response data. e.g. await (await fetch(url)).text() vs await r2(url).text.

phil-lgr commented 5 years ago

for one, node-fetch does not support https (certificate and key) like request

see https://github.com/bitinn/node-fetch/issues/15#issuecomment-97295714

phil-lgr commented 5 years ago

oh, actually node-fetch supports https / ca / cert and key: https://github.com/bitinn/node-fetch/issues/15#issuecomment-97368725

mrchief commented 5 years ago

Lots of thumbs down but @ljharb 's comment is accurate: Fetch's author specifically states he designed it as a low level HTTP/S client. Hence fetch doesn't use content types, encode query strings, etc.

All it lacks is a citation...

ljharb commented 5 years ago

Google yielded https://medium.com/cameron-nokes/4-common-mistakes-front-end-developers-make-when-using-fetch-1f974f9d1aa1 , but a better source is https://jakearchibald.com/2015/thats-so-fetch/