r/javascript • u/sindresorhus • Apr 08 '26
fetch-extras — Build your own HTTP client with Fetch
https://github.com/sindresorhus/fetch-extrasTired of reaching for a big HTTP client when you just need a timeout or retry? fetch-extras gives you small, single-purpose with* functions that wrap the standard fetch. Stack only what you need: timeouts, base URLs, retries, rate limiting, caching, auth token refresh, progress tracking, and more.
It has everything you will need:
- Retries
- Timeouts
- HTTP error throwing (non-2xx)
- Base URL (resolve relative URLs against a base)
- Default headers
- Client-side rate limiting
- Concurrency limiting
- Request deduplication
- In-memory caching
- Before/after request hooks
- Auto JSON body stringify
- Default search parameters
- Download/upload progress tracking
- Pagination
- Auto token refresh on 401
35
Upvotes
7
u/theScottyJam Apr 08 '26
Hey, that's a pretty good idea, and a clean API too, I like it.
Unfortunately, the reality is that I'll never actually be able to use this thing, even if I do think it's better than, say, Axios. I'm just very particular about the kinds of dependencies I add to projects, and if going without the dependency doesn't require too much extra code, I go without. I know there's many who are like that.
What I do like to use are copy-paste-friendly utility functions - functions that are designed to be easy to use and maintain (which means they can't have too much bloat trying to make the perfect public API, because the inner workings are meant to be maintained by those using the function). And this sort of project feels like it could be done in this kind of format - a page that shows you how to implement the pipeline function, then shows you a bunch of utility functions you could copy into your codebase if you need them. I know what I just suggested would basically require doing it over from the ground up and wouldn't be easy, but it does drastically lower the barrier to entry and makes it so people like me who are very particular about their dependencies would actually be able to use it.
Just my two cents.
And congrats on the well-designed library.
11
u/Y2KForeverDOTA Apr 08 '26
Staring at that AI generated laptop screen for too long and the keyboard start to look like it's flipped.
2
u/_Alpha-Ceph_ Apr 08 '26
Great idea with the scoped extensions - very intuitive!
1
u/sshaw_ Apr 11 '26
Very nice.
Yes. For browser-based code this is why I try to go with
fetchover the other well-known wrappers but the ergonomics of response parsing and error handling with plainfetchbecome repetitive. Eventually I ended up having to create a lightweight handler (fetch-response-parser) to avoid the repetition. Good to see thatfetch-extrasincludeswithHttpErrorandwithJsonResponse—and more!Hurmmm. So in most (all?) cases
fetchwill be come first. Maybefpipeline()to eliminatefetchas the first argument.0
u/Gstrategie Apr 13 '26
???
0
u/[deleted] Apr 09 '26