41
loading...
This website collects cookies to deliver better user experience
axios
.get(url, {
headers: {
'Content-Type': 'application/json',
},
timeout: 1000 * 60,
})
.then(res => {
})
.catch(err => {
})
fetch(url)
.then((response) => response.json())
.then((json) => {
})
.catch(() => {
})
npm i axios
axios
.post(url, jsonObject, {
headers: {
method: "POST",
headers: {
"Content-Type": "application/json",
},
},
timeout: 1000 * 60, // 1 min
})
.then((res) => {
if (res) {
return res.data;
}
})
.catch((err) => {
return err;
});
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(jsonObject),
})
.then((response) => response.json())
.then((json) => {
})
.catch(() => {
});
If you want to start New React Project — Check out React Clean Architecture
axios
.post(url, jsonObject, {
headers: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
},
timeout: 1000 * 60, // 1 min
})
.then(res => {
if (res) {
return res.data; // Directly get JSON in Step - 1 Only - Managed by Axios
}
})
.catch(err => {
return err;
})
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(jsonObject)
}).then((response) => response.json()) // Response Convert To JSON in this Step - 1
.then((json) => {
// Get JSON Object Here in Step - 2
})
.catch(() => {
})
const cancelTokenSource = axios.CancelToken.source();
axios.get('/listing/1', {
cancelToken: cancelTokenSource.token
});
// Cancel request
cancelTokenSource.cancel();
Fetch - doesn’t support Cancel API request