DEV Community

Discussion on: Do you use Axios or Fetch?

haritsinh profile image
Haritsinh Gohil

There are 2 reasons to use axios over fetch

  1. Using fetch() there is a two-step process when handing JSON data. The first is to make the actual request and then the second is to call the .json() method on the response, where on axios you get json response by default.

  2. And second issue with fetch() is it does not handle exceptions as intended, it does not enter in catch block when error occurs but axios works as expected in error handling.

see this medium article for details and example: fetch vs axios

jasterix profile image
Jasterix Author

Thanks for the concise explanation! I'll check out the blog post you shared

khalyomede profile image

Months have past, and I finally switched my fetch call for axios call. So much better indeed, and I found a way to overcome issue 1. I mentioned.

What made me make do the refractor is the fact that fetch would not throw proper exception if the error code were different than 200, I manually need to check if response.ok. So axios is my go to http request tool now 🤓