axios method post data code example

Example 1: Using axios send a GET request to the address:

// Send a POST request
axios({
  method: 'post',
  url: '/user/12345',
  data: {
    firstName: 'Fred',
    lastName: 'Flintstone'
  }
});

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))