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.
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
Passionate about building great technology and connecting with people to create positive change. Happy to answer questions about transitioning to tech. Find me on Twitter @lounecl
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 🤓
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I personnaly use fetch because of 2 reasons:
data
keyfetch
Now, for 4kb more in our client bundle, this makes a pretty good tool to add in our toolbelt...
There are 2 reasons to use axios over fetch
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.
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
Thanks for the concise explanation! I'll check out the blog post you shared
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 🤓