DEV Community

Discussion on: Complete guide to Fetch API

Collapse
 
madsstoumann profile image
Mads Stoumann

It can also be a one-liner in an async block/method:

const data = await (await fetch(url)).json();
// do something with data
Enter fullscreen mode Exit fullscreen mode

Also worth mentioning is the AbortController, so you can cancel a fetch() after a set timeout:

if ('AbortController' in window) {
  const controller = new AbortController();
  const signal = controller.signal;
// etc.
Enter fullscreen mode Exit fullscreen mode
Collapse
 
rahxuls profile image
Rahul

Yea. Thanks.