axios plain 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 instance
// lets you create custom pre-configured fetch api call!
const getUser = axios.create({
baseURL: 'https://randomuser.me/api/', // we define url
timeout: 1000, // (optional) set timeout
headers: {'X-Custom-Header': 'foobar'} // pass headers
});
// use later like this
getUser().then(response => console.log(response))
Example 3: axios put
const res = await axios.put('https://httpbin.org/put', { hello: 'world' });
res.data.headers['Content-Type']; // application/json;charset=utf-8