mikeal / r2

HTTP client. Spiritual successor to request.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What does this library solve that fetch does not?

PaulBGD opened this issue · comments

And what would be the benefits over libs like axios?

my guess is that same api between node and browser?

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?

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

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

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.

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

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.

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

commented

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.

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

see node-fetch/node-fetch#15 (comment)

oh, actually node-fetch supports https / ca / cert and key: node-fetch/node-fetch#15 (comment)

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...