Axios how to use

Introduce Axios how to use

by oktaviardi pratama

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js"></script>
<span class="result"></span>

JavaScript

// find elements
const result = document.querySelector('.result');


    const data = new URLSearchParams();
    data.append('grant_type', 'client_credentials');
    data.append('client_id', 'shin-chan');
    data.append('client_secret', 'qJigQFXNhWZ-K3NK');
    
axios.post('https://id8.shortlyst.ai/auth/token', data, {
headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
})
  .then(function (response) {
    console.log(response.json())
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .finally(function () {
    // always executed
    console.log('I always Execued');
  });