axios() object javascript code example
Example 1: include axios in javascript
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
Example 2: axios get
const axios = require('axios');
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.then(function () {
});
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.then(function () {
});
async function getUser() {
try {
const response = await axios.get('/user?ID=12345');
console.log(response);
} catch (error) {
console.error(error);
}
}
Example 3: what is axios used for
Axios is a Promise-based HTTP client for JavaScript which can be used in your
front-end application and in your Node. js backend. By using Axios it's easy
to send asynchronous HTTP request to REST endpoints and perform CRUD
operations.
Example 4: axios get
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});