What's the best way to make a REST API request in JavaScript? or How do I properly handle a REST API

20 Replies, 1243 Views

"Struggling with REST API request javascript—any tips?"

Hey guys,

I’ve been trying to figure out how to make a rest api request javascript style, but it’s not working like I expected.

Tried using `fetch()`, but sometimes it just... doesn’t do anything? Or I get weird errors.

Am I missing something obvious? Like, do I *always* need to handle the response with `.then()`? And what’s the deal with async/await here?

Also, how do you guys handle errors? My code just crashes if the API is down lol.

Any quick examples or common pitfalls to avoid? Thanks in advance!

(PS: If you’ve got a favorite library for this, lmk!)

Messages In This Thread
What's the best way to make a REST API request in JavaScript? or How do I properly handle a REST API - by - 14-07-2024, 08:25 AM



Users browsing this thread: 1 Guest(s)