Why does quasar recommend axios? #17309
Replies: 1 comment 1 reply
-
You can use a search engine to find reasons, here is a Reddit post about this: Personal thoughts and experience: I like the smaller benefits such as automatic JSON handling, throwing errors when an HTTP error happens, etc. However, configuring defaults such as a base URL, or being able to use interceptors such as one passing authorization header to all calls, are some of the more important features. I have worked on projects that had different APIs with different URLs and different authentication mechanisms, and Axios was really handy. If you don't need any of these and need to make only a few calls, then // a small example displaying the smaller benefits
// fetch
const response = await fetch('/test', {
method: 'POST',
body: JSON.stringify({
foo: 1,
bar: true,
}),
});
if (!response.ok) {
throw new Error('HTTP Error');
}
const data = (await response.json()) as { baz: string };
// axios
import axios from 'axios';
const { data } = await axios.post<{ baz: string }>('/test', {
foo: 1,
bar: true,
}); As for the documentation part, it was created in #3058, which is ~6 years old. Back in the day, things were different and there was also the need for IE11 support, which Axios had. So, it was a good recommendation. Today, it can be recommended, but not always the best solution. |
Beta Was this translation helpful? Give feedback.
-
In the documentation there is this page:
https://quasar.dev/quasar-cli-vite/ajax-requests/
where it says
We recommend selecting Axios during project initialization.
. I would like to know the reason for this. Doesn't "fetch" more or less do everything axios does. So its more a matter of taste? Except that axios makes your webpage larger? Or are there any other reasons for using axios isntead of the built-in fetch? like when I do SSR (I haven't done SSR yet, so I don't know too much about that)?Beta Was this translation helpful? Give feedback.
All reactions