Simplest Way to Fetch API Using Fetch Method

Javascript fetch api

In this example, we’re fetching data from API. The then() method is used to handle the response, converting it to JSON using the json() method. The second then() block logs the retrieved data to the console, and the catch() block handles errors if the request fails.
API URL :  https://jsonplaceholder.typicode.com/todos/

JAVASCIPRT

API url declared in const (url = “https://jsonplaceholder.typicode.com/todos/”) , we have declared a variable to store the response from api to the variavle (apiData), so when fetch function runs , it will fetch the url and get the data as a response and if there is any error in API or API server then is will throw an error as console.log(error).

Further reading