Category: javascript
Fetch API
Published on 16 Jul 2026
Explanation
The Fetch API is used to send HTTP requests from JavaScript.
Code:
fetch('https://api.example.com/users');
Explanation
The response is converted to JSON using response.json().
Code:
fetch(url) .then(res => res.json());
Explanation
Fetch returns a Promise.
Code:
fetch(url).then(data => console.log(data));
Explanation
POST requests send data to the server.
Code:
fetch(url,{method:'POST'});
Explanation
Errors can be handled using catch().
Code:
fetch(url).catch(err => console.log(err));