axios base instance delete code example

Example 1: axios delete request payload

//instead of
axios.put(url, { foo: "bar" });

//wrap the data in the data propery of a new object
axios.delete(url, { data: { foo: "bar" } });

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