how to use a fetch code example
Example 1: how to create a fetch function
const url = 'http://api.open-notify.org/astros.json'
const fetchurl = (url:string):void=>{
fetch(url).then(res=>res.json()).then(jsonRes=>{
console.log(jsonRes)
})
}
fetchurl(url)
Example 2: fetch api tutorial
fetch('https://api.github.com/users/manishmshiva', {
method: "GET",
headers: {"Content-type": "application/json;charset=UTF-8"}
})
.then(response => response.json())
.then(json => console.log(json));
.catch(err => console.log(err));