axios integrates better with TypeScript interfaces, however, fetch (and well as node-fetch) has much more predictable output.
// Is it `string` or `Record<string, unknown>` (or `Blob`)?const{data}=awaitaxios.get('/api')// Nearly always `Record<string, unknown>`constdata2=awaitfetch('/api').then((r)=>r.json())
Also, fetch can be attached AbortController. I would be interested in a library built on top fetch.
I know there are superagent and ky, but I never really tried.
I prefer axios's API and also fetch doesn't throw an error when we get a non 200 response from the backend except for Network errors. Which is why I use redaxios, the best of both worlds.
My opinion is to use axios, because in some cases like if we have to show the progress of our request then it will be very difficult to handle this using fetch method but axios have a good managed function for that case.
Also axios provides good documentation for the function and there use.
All of these are better than my first AJAX program: I didn't know JavaScript has closures, so that every XMLHttpRequest object is a global variable. It's 2006, when everyone was using IE6, I just read a book about AJAX, I haven't heard about Prototype.js, and jQuery existed for less than a year.
Most old browser will not understand fetch API and that is where, axios shines. Axios accommodates fetch API. However i think fetch API makes code look neater and a Lil bit synchronous. If I want compatibility, I'll pick axios else its fetch.
If the application needs to be light and have only a few http calls, then I would generally go for either fetch or xmlHTTPRequest. For applications that are dependent on a lot of HTTP calls, then I think axios is the best approach and its easy to get away with setup.
I'm a JS Subject Matter Expert (SME) that has spent the past few years spearheading curricula and teaching initiatives at colleges and bootcamps, in person and virtually.
fetch is fine. I don't mind the 'double await' Usually, I move 'api' functionality to its own module/file anyway, so I am not typing it more than once.
I use Fetch when the project is small or when I know it will not grow much. I prefer to use Axios in projects where requests carry more information since Axios allows you to configure an instance of it.
I am a frontend developer focused in creating application with React, Vue and Svelte. Currently, I am a software engineering student at Kasetsart University.
I would go with axios. It has nice API, and I never felt good with fetch. Dunno why, but axios feels so much more natural to my mind. It's really easy to use.
axios
integrates better with TypeScript interfaces, however,fetch
(and well asnode-fetch
) has much more predictable output.Also,
fetch
can be attachedAbortController
. I would be interested in a library built on topfetch
.I know there are superagent and ky, but I never really tried.
What about?
Now
data
is an array of objectsFruit
Actually, it's just a fake typing.
It depends on the "real" data, whether it gets
JSON.parse()
or not.jQuery.ajax()
🤦
That legendary function 😂
been there, done that 😂😂
I prefer
axios
's API and alsofetch
doesn't throw an error when we get a non 200 response from the backend except for Network errors. Which is why I use redaxios, the best of both worlds.+1
My opinion is to use axios, because in some cases like if we have to show the progress of our request then it will be very difficult to handle this using fetch method but axios have a good managed function for that case.
Also axios provides good documentation for the function and there use.
$.getJSON()
$.getScript()
Don't forget
$(selector).load(uri)
.All of these are better than my first AJAX program: I didn't know JavaScript has closures, so that every
XMLHttpRequest
object is a global variable.It's 2006, when everyone was using IE6, I just read a book about AJAX, I haven't heard about Prototype.js, and jQuery existed for less than a year.
Axios.
API things like,
data
object which I guess good security practice as well.axios.create
.More things.
Also, works really well with TypeScript which other user has mentioned.
I use both, but mostly just stick with
fetch
andnode-fetch
😎Most old browser will not understand fetch API and that is where, axios shines. Axios accommodates fetch API. However i think fetch API makes code look neater and a Lil bit synchronous. If I want compatibility, I'll pick axios else its fetch.
Fair enough 😉
If the application needs to be light and have only a few http calls, then I would generally go for either
fetch
orxmlHTTPRequest
.For applications that are dependent on a lot of HTTP calls, then I think
axios
is the best approach and its easy to get away with setup.fetch
is fine. I don't mind the 'doubleawait
' Usually, I move 'api' functionality to its own module/file anyway, so I am not typing it more than once.I use Fetch when the project is small or when I know it will not grow much. I prefer to use Axios in projects where requests carry more information since Axios allows you to configure an instance of it.
Fetch can't handle 401 response, with no access to headers. Digest authentication is a problem.
Axios
Axios
has more browsers compatibility.I prefer fetch API as I expect user to have slightly modern browser. I don't want to support outdated browser.
I’ve moved from Axios to Fetch. Axios is easier to use, but Fetch doesn’t add anything extra. Therefore, I’m mostly using Fetch now.
I haven't tried
fetch
yet, butaxios
is a delight to use, and I already know what to expect with it.I would go with axios. It has nice API, and I never felt good with fetch. Dunno why, but axios feels so much more natural to my mind. It's really easy to use.
Same here 😉
For backend: superagent
For frontend: fetch
fetch + node-fetch.
Because fetch is native, and node-fetch has the same syntax, so i can copy paste code from front to back.