In order to call the RESTful API, we will use the Fetch API (https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). It is a standard API of the web, supported by most modern browsers. Fetch defines an interface for fetching resources across the network that is similar to the one of XMLHttpRequest (also known as XHR): https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest.
Fetch has a couple of main concepts:
- Request (https://developer.mozilla.org/en-US/docs/Web/API/Request) represents a request for a resource.
- Response (https://developer.mozilla.org/en-US/docs/Web/API/Response) represents the response and its metadata.
We can configure the request as needed, for example, by adding credentials, defining the HTTP method (for example, GET, POST, and many others), adding HTTP headers (for example, Content-Type), adding a body, and more...