-
Notifications
You must be signed in to change notification settings - Fork 165
Use fetch instead of axios #314
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
Conversation
My simple benchmarking of small HTTP requests measures that Nano "11" would be 0 to 10% faster than Nano 10.1.
^ my reading of these findings is that the smaller the response payload, the more the efficiency gains of using |
It's pretty easy to stop the code handling callbacks, then it's just removing some tests, changing the README and migration guide. It would be a bigger breaking change ofc. what do you think? |
we don’t have to drop callbacks in this PR, but when we release main with this PR, we should bump the major version number and when we do that, we can also drop the callback api |
… callback variant
I went ahead and removed callbacks from the code, the Typescript definitions, the tests, the migration guide and the README. The work is in a branch here https://github.com/apache/couchdb-nano/tree/remove-callbacks (branched from the fetch branch). We can either
|
I’d say 2 and commit to supporting Nano 11 for another 12 months so folks have time to upgrade? |
Merge branch 'remove-callbacks' into fetch
I've merged in the remove-callbacks branch, so this PR now also removes support for callbacks as well as making this library dependency free 💥 |
any updates on this? |
Seems like an exciting PR @glynnbird! As mentioned in #349 and #307, I am very interested in this one too! Anything I can do to help move this along into New to |
No conflicts! Nice work @glynnbird! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments (about comments...)
+1 to the no-deps movement and the code change is mechanical in many places and you clearly understand the axios->fetch changes well and have described the breaking changes aspect.
This needs squashing before merging into one commit unless there's any meaningful split worth keeping (I don't see one fwiw)
Thanks @rnewson ! |
🎊 🚢 Nice work @glynnbird; and I see that this made it into 11.0.0 an hour ago too! Have the updated package deployed in a staging environment. I see the breaking changes, with notes on Thank you! |
Overview
Replaces
axios
HTTP library withfetch
, powered-byundici
. The upshot of this is that we reduce the number of dependencies to zero.Comments and advice welcome.
fetch
Some history: originally Nano was built on top of the request library which was later deprecated. At this point I reworked it to use axios instead. This PR eliminates
axios
and other axios-related dependencies and instead uses the new kid on the block: thefetch
API.The
fetch
feature has found widespread adoption in web browsers as a means of handling outbound HTTP requests. It has found its way into Node.js as a global function and is marked as an experimental feature in Node 18/19 and is mainstream in Node 20 and beyond.Node.js's
fetch
capability is powered by the undici package which is bundled with Node.js and in turn uses Node's low-level network libraries instead of being based on the higher-levelhttp
/https
built-in modules. It purports to be significantly faster (according to its own benchmarks) than traffic routed throughhttp
/https
modules, as is the case with other HTTP libraries likeaxios
&request
.Automated testing
Replacing
axios
withfetch
means also ditching the nock library for mocking HTTP requests and responses, because nock works by intercepting requests originating from thehttp
/https
layer, which is bypassed byundici
. Fortunately,undici
provides its own Mocking tooling.The outcome
This branch's needs no runtime dependencies. Current dependencies:
Post-PR dependencies:
Backwards compatibility
None of Nano's API has changed except when a user is supplying non-default connection handling parameters. Gone is
requestDefaults
which dates back to the "request" days and instead an optionalagentOptions
can be provided which is documented in the README and in TypeScript.Node versioning
As Node 16 is EOL, we can release v11 of Nano and make it the Node 18+ version. The v10 series of Nano would still be supported for the time being for older versions of node.
Testing recommendations
The test suite has been rewritten to use the built-in Node.js test runner (one fewer dependency!) and uses the
undici.MockAgent
to simulate responses for each of Nano's API calls, just as Nock did previously.Run with:
GitHub issue number
Fixes #307
Related Pull Requests
n/a
Checklist