[ javascript ] axios : AJAX request

GET Example ( axios.get(url[, config]) )

import axios from 'axios';

axios.get('https://www.googleapis.com/youtube/v3/search', {
  params: {
    key: API_KEY,
    type: 'video',
    part: 'snippet',
    q: searchTerm
  }
})
.then(response => console.log(response))
.catch(function(error) {
console.log(error);
});;

// response.data.items.0.id

// response.data.items.0.snippet

GET with header Example

import axios from 'axios';

axios.get(`${ROOT_URL}/3/account/me/images`, {
headers: {
Authorization: `Bearer ${token}`
}
});

// response.data : data by axios

POST with formData and Header ( axios.post(url[, data[, config]]) )

axios.post(`${ROOT_URL}/3/image`, formData, {
        headers: {
          Authorization: `Bearer ${token}`
        }
      }

axios.put(url[, data[, config]])

axios.delete(url[, config])

 

Vue this.$http

replace vue this.$http with axios ( https://vuejs.org/v2/cookbook/adding-instance-properties.html#Real-World-Example-Replacing-Vue-Resource-with-Axios )

  • this.$http.get
  • this.$http.post
  • this.$http.put
  • this.$http.delete
this.$http.get('/whatever/whatever')
.then(response => {
//response.data;
});

ref : https://github.com/axios/axios

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s