Fetch GET Request

Make a GET request using the Fetch API.

Code

JavaScript
const response = await fetch("https://api.example.com/users");
const data = await response.json();

if (!response.ok) {
  throw new Error(`HTTP ${response.status}`);
}
console.log(data);

Line-by-line explanation

Expected output

{ users: [...] }

Related snippets

Related DuskTools