Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Next Js right way to call external api

I have NextJs front from which i need to do calls to external python api. I'm new to Next and i just found out that there is integrated api (by creating folders app/api/resource/route). So what is the proper way to call external resource?

  1. Do it just using fetch/axios as you'd did it in react?

  2. Call NextJs's integrated api and then redirect from that to external?

Does second variant make any sense at all or am I tweakin?

like image 972
fabfabfab Avatar asked Sep 02 '25 17:09

fabfabfab


1 Answers

You can evaluate both options by looking at their pros and cons.

You should use API routes if you are accessing some resources that you don't want to be exposed to on the client side or if you want to do any background work.

You can go with Axios/fetch if you don't have any resources to hide and don't want to add a layer of API routes and processing. Both options have their pros and cons; you can refer to some guides about that.

like image 177
Alish Satani Avatar answered Sep 05 '25 06:09

Alish Satani