Loading video...

Video Failed to Load

Go Home

You might be using `fetch` wrong...

411,232 views • 3 years ago •via X (Twitter)

10 Comments

Steve (Builder.io)'s profile picture
Steve (Builder.io)3 years ago

If you are interested in wretch, the tiny wrapper around fetch, you can learn more about it here

Steve (Builder.io)'s profile picture
Steve (Builder.io)3 years ago

For a cool trick to make `fetch` more intuitive without using any libraries see pt 2 here:

Germinal Camps's profile picture
Germinal Camps3 years ago

Or you could just use axios…

Steve (Builder.io)'s profile picture
Steve (Builder.io)3 years ago

True, though it is over 5x larger (11kb gzip vs 1.9kb gzip), so if perf is important for your site/app minimizing kb can be valuable

Tanguy Krotoff's profile picture
Tanguy Krotoff3 years ago

I've written a small fetch wrapper (~250 lines) that does this. - Comes with test utilities - Supports Node.js & web browsers - Written in TypeScript - Fully tested const response = await postJSON(url, data).json();

Steve (Builder.io)'s profile picture
Steve (Builder.io)3 years ago

Oo I like

Simon Vrachliotis's profile picture
Simon Vrachliotis3 years ago

The delivery on these tips is amazing, congrats! Love the karaoke-like transcript progress 👍

Steve (Builder.io)'s profile picture
Steve (Builder.io)3 years ago

Thanks Simon!

Steve (Builder.io)'s profile picture
Steve (Builder.io)3 years ago

Wrote more on this in my latest blog post:

Franco Valdes's profile picture
Franco Valdes3 years ago

That was one of my biggest issues when fetch came out. I wish non 200 responses would automatically fall into the catch but they do not.

Related Videos