Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I am still more fond of jQuery's ajax functionality than anything that followed, including the fetch API.


I've always liked to use axios which provides a jQuery-ish AJAX library. Works in the browser and server-side with NodeJS.

https://github.com/axios/axios

Much nicer to use than fetch IMHO


This.


Why? fetch returns a native promise, which are _much much much_ nicer to work with than XHR ever was or desired to be.

Good riddance.


Straightforward error handling both for actual http numbered errors, and for transport errors (site down/DNS/etc).


For one, fetch() doesn’t support progress reporting.


It does. The fetch response object exposes a `ReadableStream` through the `body` property, which you can loop through with a `for await ... of` loop. On each iteration, simply update your progress.



Yep, that’s a cute hack. Now what would be the equivalent of that for file upload? There’s no such API for fetch() because there’s no writeable body stream for requests. QED


I'm not particularly familiar with fetch, but does this do what you want? https://github.com/SitePen/javascript-streams-blog-examples/...


This is a hack that works only for downloads via streams. It won’t work e.g. for file uploads (unless you read the file into memory first, which is highly undesirable).


Missing .abort() on safari is one reason. https://caniuse.com/#feat=abortcontroller



jquery also returns a promise


I’d say that modern web patterns exist only because of jQuery. jQuery adapted the DOM and did for JS what LINQ did for C#. Replace datastore for DOM.

JavaScript itself has subsumed most of jQuery and replacements like lodash would not have existed without it.

Browsers will catch up badly.


fetch is very bleh, so that's not a high bar. What I'd love to see is more Observable-based offerings in that space... RxJS has some rudimentary client, but seeing that pushed further would be great.


You should look at `for await ... of`[1]. You can get a streaming reader from a `fetch` response and loop if through an async iterator. If you prefer the functional syntax observables, I'm sure you can find a library that wraps async iterators as observables.

[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...


It's not to get a stream so much as it is to get automatic aborts in mergeMaps and such. Amazing for things like auto-complete from an API as you type.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: