Fetch API
Hello there,
In this entry, I would like to share one way to get JSON data from a Rest API that I find useful.
The Fetch API provides an interface to access and manipulate requests and responses. Fetch is a good way to avoid a ‘callback mess’ since it uses Promises. The Fetch API possesses a method named fetch() which fetch a resource.
A basic syntax for a fetch() function looks like this:
Something important to keep in mind is that when the promise is resolved we are getting the response header but not the response body.
In order to get the actual data (response body), we do the following:
Fetch API is a great way to make asynchronous requests, handle responses using JavaScript promises in the process.