Next.js Discord

Discord Forum

Axios vs Fetch

Answered
Havanese posted this in #help-forum
Open in Discord
HavaneseOP
Hello! Quick question
I have been seeing a lot of questions about Axios vs. Fetch, and when I understand that you can manually use Fetch to solve many of the things Axios does quickly the recommendation is Fetch for server-side rendering (react server components)
However, Can I keep using Axios with Server-side rendering? If not, why? and if you have any tutorial Axios integration that would also be great :meow_meow:
Answered by DirtyCajunRice | AppDir
there is literally no benefit to using axios anymore
View full answer

12 Replies

European sprat
You can but you lose all the caching and revalidation stuff that's built in to app directory
there is literally no benefit to using axios anymore
Answer
HavaneseOP
Today Axios offers an elegant way to use Interceptors (for example) which in Fetch IMHO isn't
Masai Lion
what about response (error handling) and request (access token attachment) interceptors?
@Havanese Today Axios offers an elegant way to use Interceptors (for example) which in Fetch IMHO isn't
why exactly is it elegant? Its just a single function that they injected into the namespace.
interceptors, as a whole, are - at best - a convenience function that you could simply write without dot notation. At worst they cause undesired results globally because of a config in one place
It is important to differentiate a feature from a lazy method
plus axios does not work in Edge Runtime, Cloudflare Worker.
HavaneseOP
thank you for the feedback! It helps me a lot, do you have any recommendations about the best practices on Fetch for Interceptors?
@Havanese thank you for the feedback! It helps me a lot, do you have any recommendations about the best practices on Fetch for Interceptors?
If you have a commonly used catch, id just make a function that includes that logic. fetchWithReqMutate() etc
or if you want to get the “axios feel” make a "fetchios” class and add req / resp array properties. can accomplish the same thing