Fetch JSON from API

Make a GET request and parse the JSON response.

Code

Utilities
const response = await fetch('https://httpbin.org/get');
await response.json();
Browser·fetch() may be limited by CORS

With Error Handling

const response = await fetch('https://httpbin.org/get');
if (!response.ok) throw new Error(`HTTP ${response.status}`);
await response.json();

More JavaScript Snippets