I remember back in the days of jQuery
$.ajax was a big, big thing. But nowadays we have
fetch a way cooler, faster solution to fetch data from an API endpoint. It is the better alternative to XHR and AJAX. The best part: the Fetch API request works in
How to make a GET request with the Fetch API permalink
That is as basic as it gets, won't do much since we are not returning any data.
Returning json data with the Fetch API permalink
// Successfull fetch return as json
// Data now contains the json
// A Error occured
The first API response will return an object, not an actual response, so we need to tell the promise that we want to return the response as JSON data.
You can play around with this codepen.
Browser support for Vanilla JS API requests permalink
The Fetch API has excellent support, but not in IE. 😓
You can use a polyfill for this.