axios
npm i axios
axios
npm i axios
axios get
const axios = require('axios');
// Make a request for a user with a given ID
axios.get('/user?ID=12345')
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.then(function () {
// always executed
});
// Optionally the request above could also be done as
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.then(function () {
// always executed
});
// Want to use async/await? Add the `async` keyword to your outer function/method.
async function getUser() {
try {
const response = await axios.get('/user?ID=12345');
console.log(response);
} catch (error) {
console.error(error);
}
}
axios
axios.get('url')
.then((response) => {
// Code for handling the response
})
.catch((error) => {
// Code for handling the error
})
axios post
//EXAMPLE INPUTS
const url='/'
const data={
name1:value1,
name2:value2
}
//ACTUAL USAGE
const parsedData = new URLSearchParams();
Object.getOwnPropertyNames(data).map((property) =>
parsedData.append(property, data[property])
);
axios
.post(url, parsedData)
.then((res) => {
//handle result
})
.catch((err) => {
//handle error
});
axios
const axios = require('axios'); // Make a request for a user with a given IDaxios.get('/user?ID=12345') .then(function (response) { // handle success console.log(response); }) .catch(function (error) { // handle error console.log(error); }) .finally(function () { // always executed }); // Optionally the request above could also be done asaxios.get('/user', { params: { ID: 12345 } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }) .finally(function () { // always executed }); // Want to use async/await? Add the `async` keyword to your outer function/method.async function getUser() { try { const response = await axios.get('/user?ID=12345'); console.log(response); } catch (error) { console.error(error); }}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us