Fetch API is a modern, promise-based interface for making network requests. It's commonly used to get data (e.g., JSON) from a server.
javascript
// Fetching data from a public API
async function getData() {
try {
const response = await fetch('https://jsonplaceholder.typicode.com/todos/1');
const data = await response.json();
console.log(data);
} catch (error) {
console.error("Could not fetch data:", error);
}
}
getData();You should see
{ "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false }