fetch() API is has capable of reproducing the key features of Axios, it also work with all modern browsers.
fetch() method is used to send the requests to the server without refreshing the page.
It is an alternative to the XMLHttpRequest object and Axios.
fetch() uses body property to send to data to endpoint and Axios Used data property .
fetch() do not get automatically server data return or response needs to call the response.json()
method to parse the data to a JavaScript object.
Axios automatically will get server response data.
fetch() will support only latest browsers
Axios support all browsers even old browsers because it is based on XMLHttpRequest
=======================
const getUsers = async()=>{
try {
const comingData = await axios.get("https://gorest.co.in/public/v2/users")
return comingData.data
} catch (error) {
return error
}
}
const displayData = async() => {
const data = await getUsers()
console.log(data)
}
displayData()