DEV Community

Javico11
Javico11

Posted on

Which is better? Axios or Fetch?

Personally, I like the simplicity of both, but I use more Axios, I would like to know your opinions about it.
I attach an example of the basic use of Axios:

const fetchData = async() => {
   try{
     const get_data = await axios.get("URL");
   }
   catch(error){
     console.log(error);
   }
 }

 // call the function
 fetchData();
Enter fullscreen mode Exit fullscreen mode

This has really helped me a lot and I have no complaints, but when talking about performance and being an external library, this question arises.

thanks for reading :D

Top comments (2)

Collapse
 
sebastian_wessel profile image
Sebastian Wessel

I used native fetch for the first time now, and I like it.
The Rust-style with response.ok instead of throwing is easier to handle/read.
Also, the timeout handling, JSON en/decoding is working out of the box.
If you do not need to support node versions which do not provide native fetch - go for fetch

Collapse
 
javicodev11 profile image
Javico11

Tks Sebastian for your kind opinion, if I have read a little about those advantages.