Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative libraries to request #3143

Open
reconbot opened this issue Apr 1, 2019 · 103 comments
Open

Alternative libraries to request #3143

reconbot opened this issue Apr 1, 2019 · 103 comments
Labels
neverstale Something that lasts forever

Comments

@reconbot
Copy link
Contributor

reconbot commented Apr 1, 2019

Since the announcement of request going into "maintenance mode" (full details in #3142) I'd like to collect a list of alternative libraries to use. Please comment below and I'll update this table. When we have a list of good alternatives we should add this to the readme.

In no particular order and dreadfully incomplete;

Package Name Bundle Size API Style Summary
node-fetch 0.4kb promise / stream A light-weight module that brings window.fetch to Node.js
bent 1kb fp / promise / stream Functional HTTP client w/ async/await
got 48.4kb promise / stream Simplified HTTP requests
make-fetch-happen 442kb promise / stream make-fetch-happen is a Node.js library that wraps node-fetch-npm with additional features node-fetch doesn't intend to include, including HTTP Cache support, request pooling, proxies, retries, and more!
axios 11.9kb promise / stream Promise based HTTP client for the browser and node.js
unfetch 1kb promise / stream Tiny 500b fetch "barely-polyfill"
superagent 18kb chaining / promise Small progressive client-side HTTP request library, and Node.js module with the same API, sporting many high-level HTTP client features
tiny-json-http 22kb promise Minimalist HTTP client for GET and POSTing JSON payloads
needle 164kb chaining / promise The leanest and most handsome HTTP client in the Nodelands
urllib 816kb callback / promise Help in opening URLs (mostly HTTP) in a complex world — basic and digest authentication, redirections, cookies and more.
@reconbot reconbot added the neverstale Something that lasts forever label Apr 1, 2019
@jeffscottward
Copy link

jeffscottward commented Apr 1, 2019

As a frontend focused guy who also does node.js from time to time, axios has been my go to.
Easy API, from Facebook, works on browsers and node? Done

@bnb
Copy link

bnb commented Apr 1, 2019

Per a recent discussion with @mikeal, I have Bent a try. As a Node.js developer whose been using request for a while now, bent was definitely an easy transition - highly recommended 💖

@paambaati
Copy link
Contributor

paambaati commented Apr 1, 2019

@reconbot You might want to add got, needle and urllib.

@simov
Copy link
Member

simov commented Apr 1, 2019

Well, it feels kind of wrong to promote my own little library here, but since that's the goal of the issue, here it is: request-compose is a functional, 0 deps HTTP client with support for promises, streams, and a bunch of other useful options, most of which are very close to the ones found in request.

I also wrote an article about it. The general idea is that everyone is encouraged to compose their own HTTP clients, specifically tailored to their own needs.

As for the bundle size, I've no idea, but it should be pretty small, though this client was never designed to be used in the browser.

@csantanapr
Copy link

It might be good to add the following columns to the table:

  • Number of stars in Github (yes I already know this is not the only factor when choosing a lib)
  • Number of npm downloads (maybe weekly, same stat as npm website, and yes I already know this is not the only factor when choosing a lib)

When putting side by side these numbers some libs have thousands of stars and million of downloads weekly, vs others in the hundreds.

My 2 cents, OK to ignore and move on, no need to correct or dispute the comment.

@reconbot
Copy link
Contributor Author

reconbot commented Apr 1, 2019

@csantanapr I agree, it might be worth comparing feature sets too. Proxy support, cache support, auth features etc. If you use a specific feature of request and need to find it elsewhere, this would be a good time to talk about it.

@kreig303
Copy link

kreig303 commented Apr 1, 2019

axios gets my vote, especially as a front-ender.

@JamesMGreene
Copy link
Contributor

JamesMGreene commented Apr 1, 2019

Worth a look: ky (frontend) and ky-universal (isomorphic)

@rmngrc
Copy link

rmngrc commented Apr 2, 2019

Axios user here. That way, all our teams can use the same library regardless the environment: browser or nodejs (running in server or serverless). Very well maintained, and all our people love it.

@sindresorhus
Copy link

sindresorhus commented Apr 2, 2019

We have a good comparison between got, request, node-fetch, axios, and superagent in the got readme: https://github.com/sindresorhus/got#comparison
(PR welcome if you see any inaccuracies. We've tried to keep it as neutral as possible)

Got also has a migration guide for moving from request: https://github.com/sindresorhus/got/blob/master/migration-guides.md

@tracker1
Copy link

tracker1 commented Apr 2, 2019

For me, I tend to do wrappers around fetch api, so node-fetch is my goto. Despite the negative aspects, I usually load it onto global.fetch in node, so I can rely on it always being available, much like in the browser (via polyfill for older browsers). Can also use isomorphic-fetch which is pretty much a wrapper around node-fetch for node, and the fetch polyfill (or already available fetch) in browser. Since I don't have to support legacy browsers, I just use the global, and establish the global for use in node.

@vdeturckheim
Copy link

Hey, Wreck (https://www.npmjs.com/package/wreck) is what I use

@Velveeta
Copy link

Velveeta commented Apr 4, 2019

I would prefer something that mimics the fetch api on the client. Libs like axios, superagent, etc are higher level abstractions on top of a standard request library. As a replacement for the low-level request library, I'd like to see something that mirrors the low-level equivalent on the client for the purposes of universal js development. Libs like axios and superagent can then just reimplement themselves on top of that, and its users can continue using them, but those shouldn't be considered foundational for this purpose.

@kreig303
Copy link

kreig303 commented Apr 4, 2019

@Velveeta I went and looked at the axios codebase and see no evidence that it is based on a "lower-level standard request library". Please tell me how you came to this conclusion?

@reconbot
Copy link
Contributor Author

reconbot commented Apr 4, 2019

@sindresorhus's comparison is by far the better approach than my list above. https://github.com/sindresorhus/got#comparison

node-fetch/isomorphic-fetch is a suitable low level building block for most clients. I'd love to see a fetch based request shim.

@simov
Copy link
Member

simov commented Apr 4, 2019

I would wrap fetch with nicer API any day. Well, I guess that's just a matter of preference, but implying that the fetch API is great just because it's a defacto standard in the browsers is just wrong. I know it's less noise to have it isomorphic on both sides, but that don't make it any better.

@dar5hak
Copy link

dar5hak commented Apr 4, 2019

There's r2 by @mikeal himself. It is meant to be a spiritual successor to request. It has a Promise API and is 16kb compressed.

@ofrobots
Copy link

ofrobots commented Apr 4, 2019

Axios may work okay in the browser, but that hasn't been our experience with it on Node.js. Also, I am not sure if it is actively maintained anymore.

image

@Velveeta
Copy link

Velveeta commented Apr 4, 2019

@kreig303 I haven't looked into the internals of axios, so I wasn't aware of that. Looks like it's currently based on regular XHR's, which makes sense, since it's a solution for both client and server requests. I simply meant that axios is pretty feature rich, and something a little more bare bones should be considered for a foundational module like a replacement for request, and then let other more feature rich libs build on top of that if they desire. I opted for something that mirrors the fetch API specifically for the purposes of having a consistent API on both client and server (like the XHR's that underly axios), and because it's the logical successor to XHR's. If a nicer API wrapper is desired, there's plenty of opportunity to wrap it and release another library with that optimal API, but I'm all for feature and API parity between client and server wherever it can be done.

@simov
Copy link
Member

simov commented Apr 4, 2019

Well, one of the issues we have in request is too many features, and too much exposed state, even the one that's considered internal. It's both a curse and a bless to have so many features. It's a bless because that's why it is so popular, and it was first. It's a curse because without a huge amount of constant effort to keep the codebase clean, straightforward, and generally exciting to work with, the project eventually dies. And that's not even a request's problem, it's the user's own perspective of always wanting to put something out of their own layer, and instead put it under the blanket somewhere else.

Well, I guess axios have the same faith ..

So what we can all do instead, is put at least some amount of effort into understanding how the wheel works, and then try to think through each individual task at hand, and see which wheel fits best.

@kreig303
Copy link

kreig303 commented Apr 4, 2019

@ofrobots that's a bit of a selective screenshot for such a popularly used library. Here's mine:
Screen Shot 2019-04-04 at 1 58 24 PM

FWIW I don't recall if I'd used it as a back-end lib, so I am in no position to verify your claims (unless you had a peculiar use case it didn't cover).

@dgrelaud
Copy link

If you need an ultra small & ultra fast NodeJS request library (< 150 LOC, no dependencies), focused on simple and reliable retries (even with streams), with many features (gzip/deflate/brotli response follow redirect, instance, ...). Here is our modest contribution:

https://github.com/carboneio/rock-req

Library NodeJS 16 NodeJS 18 NodeJS 20* Size deps inc.
rock-req 🙋‍♂️ 22816 req/s 21797 req/s 21964 req/s 144 LOC
simple-get 2937 req/s 3260 req/s 21258 req/s 317 LOC
axios 5090 req/s 4910 req/s 3196 req/s 13983 LOC
got 2163 req/s 1762 req/s 9961 req/s 9227 LOC
fetch 2101 req/s 2102 req/s 2020 req/s 13334 LOC
request 2249 req/s 1869 req/s 15815 req/s 46572 LOC
superagent 2776 req/s 2100 req/s 2895 req/s 16109 LOC
phin 3178 req/s 1164 req/s 21299 req/s 331 LOC
undici* 24095 req/s 24378 req/s 24191 req/s 16225 LOC

It is written in pure JS for performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
neverstale Something that lasts forever
Projects
None yet
Development

No branches or pull requests