axios cdn
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
axios cdn
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
header in axios
axios.post('url', {"body":data}, {
headers: {
'Content-Type': 'application/json'
}
}
)
axios post request
// axios POST request
const options = {
url: 'http://localhost:3000/api/home',
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json;charset=UTF-8'
},
data: {
name: 'David',
age: 45
}
};
axios(options)
.then(response => {
console.log(response.status);
});
axios post with header
// Send a POST request
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
},
headers: {'Authorization': 'Bearer ...'}
});
headers in axios.get
const axios = require('axios');
// httpbin.org gives you the headers in the response
// body `res.data`.
// See: https://httpbin.org/#/HTTP_Methods/get_get
const res = await axios.get('https://httpbin.org/get', {
headers: {
'Test-Header': 'test-value'
}
});
res.data.headers['Test-Header']; // "test-value"
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);
}
}
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