Coders for Causes BlogAbout

Little Trick with Axios

December 30, 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.

axios.post(endpoint, {
    data: data
}).then((response) => {
    // successful call
}).catch((error) => {
    // failed call
}).then(() => {
    // always executed
})

David Yu

Written by David Yu who loves to build things in code.You should checkout our facebook for latest events and news