Menu

1 / 4

Your fetch wrapper is missing five things. I put them in one library.

JavaScript in Plain English - Medium·Sajankumar Vijayan·about 17 hours ago
#vOZeloLl
Reading 0:00
15s threshold

Your fetch wrapper is missing five things. I put them in one library.

Sajankumar Vijayan

12 min read9 hours ago

Retries, a circuit breaker, caching, and a token refresh that doesn’t fall apart when ten requests get a 401 at once. Zero dependencies.

Almost every project that talks to an API grows the same file. It starts as three lines around `fetch`. Then someone adds a timeout. Then a retry. Then a cache. Then a token refresh. A year later it’s 400 lines, nobody wants to touch it, and it still logs users out at random on Monday mornings.

Press enter or click to view image in full size

I’ve read a lot of these files, and they tend to break in the same places. So I wrote the version I wish I’d had from the start, tested it, and published it as an npm package called fast-http-client

This post walks through what plain fetch leaves to you, why each gap bites in production, and how the library closes it.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.