Should I Switch from Axios to Native Fetch?

0
5
Asked By CuriousCoder123 On

I've been wondering if we still need to rely on libraries like Axios for HTTP requests now that the Fetch API is native in both Node.js and browsers. While Axios is great and has some useful features, I'm exploring simpler alternatives for reducing dependencies. I've come up with a few patterns to mimic common Axios functionalities with native fetch.

For instance, I created a base client pattern to handle authorization headers and base URLs. I also implemented basic retry logic and timeout handling using AbortController. These methods can provide a solid foundation, but they don't cover all features of Axios. I'd love to hear how others are managing this: Are you still using Axios, or have you made the switch to native fetch?

3 Answers

Answered By CodeSniper89 On

I’ve been moving towards native fetch for new projects. The mental overhead of maintaining an extra library like Axios just isn't worth it anymore for simple cases. Plus, wrapping fetch makes it easier to mock in tests. Just a word of caution: be careful with retry logic for non-idempotent requests! I've seen people accidentally create duplicates because they retried POST requests without checks. If you're already deep into Axios, though, migrating may not be worth the cost unless you’re doing a major overhaul.

Answered By SkepticalDeveloper On

You really don't need to worry about security issues related to dependencies if you're keeping things simple with native fetch. However, just a heads-up about storing tokens in localStorage; it's a known risk for XSS attacks. That said, fetch is perfectly fine to use! Just be aware of the risks with sensitive data.

Answered By GitGuru92 On

I’ve used Axios for a while but decided to switch to fetch for my last couple of projects. It performs well enough and helps reduce the number of dependencies I need to manage.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.