Fetch API
November 11, 2018•195 words
A HTTP library is still a common plugin to include on a project. Depending on
what I am working on I will still use jQuery to make some of these requests or
include a library like Axios to handle the requests. If you are looking for a
way to not include third-party scripts and work with native browser features
Fetch will be something that you want to start to look at for including in
your project. Lets take a look at a native way to make a GET request before
fetch. var request = new XMLHttpRequest(); request.open('GET', '/my/url',
true); request.onload = function() { if (request.status >= 200 &&
request.status response.json()) .then(json => console.log(json)) If the .then
looks unfamiliar to you. It is best to start with reading Promise - JavaScript
| MDN and learning over at MDN. Once, I started to understand promises. It
made Fetch all that much easier to understand and to play with. Fetch actually
has really good browser support so you can start using it now. Here are some
more resources on Fetch Can I Use: FetchHow to Use the JavaScript Fetch API to
Get Data Introduction to the Fetch API