axios api javascript code example
Example 1: axios cdn
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
Example 2: include axios in javascript
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
Example 3: Using axios send a GET request to the address:
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
}
});
Example 4: how to use axios get
const req = async () => {
const response = await axios.get('https://dog.ceo/api/breeds/list/all')
console.log(response)
}
req()
Example 5: Using axios send a GET request to the address:
axios({
method: 'get',
url: 'http://bit.ly/2mTM3nY',
responseType: 'stream'
})
.then(function(response) {
response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
});