13 ms·
request will stop considering breaking changes. Does the JS community seem to consider that a bad thing...? To me, this sounds more like "is becoming stable" t
by userbinator 8y ago
request will stop considering breaking changes.
Does the JS community seem to consider that a bad thing...? To me, this sounds more like "is becoming stable" than "is being deprecated".
- Sachse 8y agoNo, but `request` does not implement modern JS features such as promises and async/await which generally have become commonplace. So what this announcement means is that such features won't ever be added, and that people should look to another library for HTTP requests in "modern JS".
- sjustinas 8y agoAs I replied to tlrobinson above, is this a problem when there is an an official package that bolts on a promise support?
- tlrobinson 8y ago“requests” doesn’t support (or apparently want to support) Promises which are now widely used in the JavaScript community, thus it’s obsolete. Promises work best when all the async operations in your code use them, especially with async/await. Interestingly early versions of Node had a limited form of Promises but they were quickly removed.
- matthewaveryusa 8y agoJust to give a little bit more context, in contemporary javascscript you can write something like this (wrapped in a try-catch: async function http_request_new(url) { return new Promise(...) } const http_response = await http_request_new("https://www.google.com") ... The await signals that the asynchronous http_request function is non-blocking, and we should continue execution once the non-blocking return value (promise) has resolved. Previously idiomatic javascript would have looked like this: function http_request_old(url, cb) { return ... } http_request_old("https://www.google.com", function(error, http_response) { ... }) Luckily node.js provides util.promisify that converts any old callback-style async function into one that returns a promise, so that await can be used: http_request_new = util.promisify(http_request_old) const http_response = await http_request_new("https://www.google.com") ... Unless I'm mistaken, it's fairly trivial to promisify the old-style code
- javagram 8y agoIn the case of Request, there is already an official wrapper for the library that supports promises. https://github.com/request/promise-core https://github.com/request/promise-core It is a couple hundred lines of code though.
- Cthulhu_ 8y agoExactly - for the longest time, the success / error callback signature was the primary and expected way to handle async code in Node modules, and there was a lot of objection to using promises - in part because at the time it was not stable, and in part because its performance was less compared to callback style. You don't want to put performance bottlenecks in core and/or frequently used libraries just so it fits your preferred async style. If you REALLY want to pay that price, it's trivial to promisify a library like this - and it doesn't add complexity or size or (worst case) dependencies (like 3rd party promise libraries, as was the case for a long time) to your small, focused library.
- deleted 8y ago[deleted]
- jrochkind1 8y agoi guess these are the downsides of a platform without much stdlib. consensus stdlib doesn't really work, and then things don't work together.
- Klathmon 8y agoutil.promisify won't work on request in most places because they don't use the defacto standards of callbacks (the first argument being an error argument, callback being the last argument, etc...). Funnily enough, i believe it predates the widespread use of that convention! But that means you need to either do it yourself (which admittedly is pretty trivial), or use custom bindings to "promisify" request (which do exist! and are even maintained by the original authors). But promises are only one reason why request is more difficult to use. Compare the node.js style streams with async iteration which could be possible if the library supported it: node streams style: const readStream = fs.createReadStream(inputFilePath, { encoding: 'utf8', highWaterMark: 1024 }); readStream.on('data', (chunk) => { console.log('>>> '+chunk); }); readStream.on('end', () => { console.log('### DONE ###'); }); async iteration streams: for await (const chunk of fs.createReadStream(inputFilePath, { encoding: 'utf8', highWaterMark: 1024 });) { console.log('>>> ' + chunk) } console.log('### DONE ###') Not only is the latter easier to quickly grep and understand, but it also is easier to catch exceptions (a try/catch works, and it bubbles up! So it's harder to ignore errors by forgetting to add a `readStream.on('error'...)`), and it works correctly in async contexts so it doesn't also need to be wrapped by Promise constructors. Then throw in writeable streams, transform streams, and tons more that all require more difficult setup, less standard ways of working, and are overall harder to get completely right without any bugs.
- sjustinas 8y agoThere is an [official] additional package "request-promise" that adds Promise support. I don't dabble in Node much, but is this a bad thing? Although on the other hand, most other libraries support promises out of the box (e.g. using the "pass no callback to get a Promise back" pattern).
- nailer 8y agoThere's also axios, superagent, and a whole bunch of excellent node HTTP clients (also 'fetch' if you like encoding URLs and parsing JSON manually).
- Klathmon 8y agoBolting on the newer features as additional packages has a few downsides in my experience: * Increased complexity. So now in order to use request in a modern JS ecosystem, you need to install request, and request-promise-native, which itself installs request-promise-core, which all 3 then combine to use. Which do you look for to find documentation? Which do you look at when you have bugs? How does interop happen with other 3rd party libraries? Does every other lib that works with request have to handle all the official wrappers or just the main? And good god what happens when breaking changes are made to one of them? Everything is just a lot more complicated here. * Only so much can be easily patched on. Things like streams are pretty complicated, and writing a complicated (and often slow) runtime transformation of a stream to an async iterator, both of which don't have complete 100% matches for all of their features, means that everything is now using a sub-par incomplete interface. The main application can't implement features which take advantage of the new syntax, and the wrapper can't always represent the old ways of working perfectly. Basically, it's a leaky abstraction in most cases, which is slower, uses more memory, and is a lot more complex.
- mwilliaams 8y agoI use request-promise and it’s always worked perfectly fine. I normally do const response = await rp({ request params }); and then continue on.
- Klathmon 8y agoAs the post explains, Javascript has changed significantly since request was first created, and that left them with 3 real options: 1. Try to make massive breaking changes to the request module to make it more easy to work with in the current javascript landscape (promises, new streams, async generators, etc...). This is a problem because then the millions of blog posts, comments, stack overflow answers, and more are all now outdated and wrong. And as the author explained, it would basically be a completely new library. 2. ignore it and become a thorn in the side of devs everywhere (oh, i can use new streams and promises in 99% of my codebase, except for a few old modules that we still use or have to code around until they get removed as they are difficult to work with) 3. Deprecate request, and make a new module under a new name which can adapt to the current landscape. So if you value non-breaking changes over developer experience and complexity of integration, then it's a good thing for you. If you value tools which work with the language as it exists now rather than against it, it's also a good thing for you since the new "request by a different name" will work much better in current javsascript. This is the opposite of what Angular did. Angular 1 vs 2+ were basically different libraries. Rather than take the angular route and just increment the number and keep the name, they are trying something different. They are throwing away the name and starting fresh.
- HatchedLake721 8y agoI'll start from bottom options: 3) "deprecate request and start new" - and discard 10 years of commits, stability and tests? Wouldn't be a rational way to go. 2) "ignore it and become a thorn in the side of devs everywhere" - it wouldn't become a thorn more than it is now, would it? It's a 10 year old package that's downloaded 14 million times a week. It doesn't feel a thorn with those numbers. You can also `util.promisify` it if a callback is a "thorn" for you as a developer. (but see https://news.ycombinator.com/item?id=19604867 https://news.ycombinator.com/item?id=19604867) 1) "there are a lot of google results with solutions that the new breaking changes will make obsolete" - that's what semver and major versions are for. "We'll break Stack Overflow answers" doesn't feel like a valid reason. jQuery has had its fair share of breaking changes in the last 12 years, and we know the numbers if we compare `jQuery` vs `request` questions on Google/Stack Overflow, so again, it doesn't feel like a valid reason.