Little tricks with axios

Little Trick with Axios

by David Yu

Last Updated: 30 December 2018

Without a doubt Axios is a great HTTP client library. It simplifies and improves http requests although the new es6 http calls are nice in there own right. Something I missed with jquery's ajax calls was the .always method that would always execute regardless of the success of the call. Axios doesn't have such a method but you can simulate it with this handy trick.

jsaxios
  .post(endpoint, {
    data: data
  })
  .then((response) => {})
  .catch((error) => {})
  .then(() => {
    // always executed
  })