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 · 99 comments
Open

Alternative libraries to request #3143

reconbot opened this issue Apr 1, 2019 · 99 comments

Comments

@reconbot
Copy link
Contributor

@reconbot 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.
@jeffscottward
Copy link

@jeffscottward 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 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 paambaati commented Apr 1, 2019

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

@simov
Copy link
Member

@simov 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

@csantanapr csantanapr commented Apr 1, 2019

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 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 kreig303 commented Apr 1, 2019

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

@JamesMGreene
Copy link
Contributor

@JamesMGreene JamesMGreene commented Apr 1, 2019

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

@rmngrc
Copy link

@rmngrc 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 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 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

@vdeturckheim vdeturckheim commented Apr 4, 2019

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

@Velveeta
Copy link

@Velveeta 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 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 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 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 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 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 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 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 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).

@travist
Copy link

@travist travist commented Mar 6, 2021

Here is a simple wrapper around node-fetch that provides the HTTP_PROXY, HTTPS_PROXY, and NO_PROXY support.

https://github.com/formio/node-fetch-http-proxy

@jeanmachuca
Copy link

@jeanmachuca jeanmachuca commented Mar 28, 2021

You can see an example of using QCObjects for universal client requests here:

postmanlabs/postman-code-generators#432

https://github.com/QuickCorp/QCObjects#serviceloader

alanorozco added a commit to ampproject/amphtml that referenced this issue Apr 7, 2021
The npm package `request` has been deprecated.

request/request#3142

The main suggested alternative is `node-fetch`, which we already use.

request/request#3143

This change replaces `request` and `request-promise` users with `node-fetch`.
@PierreFritsch
Copy link

@PierreFritsch PierreFritsch commented May 20, 2021

+1 for @csantanapr's suggestion of adding numbers, and thanks to @sindresorhus for sharing the comparison:

got request node-fetch ky axios superagent
Issues open
Issues closed
Downloads
Coverage
Build
Bugs
Dependents
Install size
GitHub stars
TypeScript support
Last commit

anoadragon453 added a commit to matrix-org/matrix-content-scanner that referenced this issue Jun 11, 2021
The `request` package [has been deprecated](request/request#3143), and thus this PR aims to replace it with simple-get.
@LawsonCheng
Copy link

@LawsonCheng LawsonCheng commented Jul 16, 2021

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.

Hello, I have took the references from the API of request/request and created a new HTTP request library Poke in written typescript by myself. Appreciate if anyone can give it a try and make things better together :) Cheers🍺

https://github.com/LawsonCheng/poke

@munierujp
Copy link

@munierujp munierujp commented Aug 20, 2021

The comparison table in the README of got looks more detailed than the table here.

rochapablo added a commit to rochapablo/amphtml that referenced this issue Aug 30, 2021
The npm package `request` has been deprecated.

request/request#3142

The main suggested alternative is `node-fetch`, which we already use.

request/request#3143

This change replaces `request` and `request-promise` users with `node-fetch`.
@RussBrown00
Copy link

@RussBrown00 RussBrown00 commented Sep 3, 2021

My default would be node-fetch, but got while I've never personally used it seems interesting.

edit: Some more reflecting has me thinking that node-fetch more acceptable testing and coverage and is probably the “safer” bet. It’s really not used in more than a handful of places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet