Expo Router APIs

I am deciding what’s the best way to set up APIs for my project. My app calls external urls however I don’t want to use fetch directly in frontend components. Goal was to have a utility function to call a route that I set up in the app/ folder then take care of processing all that on the server side. Not sure if it’s just redundant coding. And also since I’m calling external urls how should I export the basic get post etc?
6 Replies
DrPorkChop
DrPorkChop5mo ago
@kronic Do you mean you don't want to have API calling logic in the component that is being rendered? Or are you trying to evaluate whether to have a seperate backend for calling the external endpoints, and then exposing endpoints to your frontend that provide you with pre-processed data?
RaiRai
RaiRai5mo ago
Ah yup I’m trying to see how to structure it best. Should I have a separate backend? Right now I’m just using +api.ts routes showed by expo
DrPorkChop
DrPorkChop5mo ago
It very much depends on your use case, if you want to manage auth or do lots of resource heavy manipulation to the data you are pulling then it sort of makes sense to. But if you are just doing simple GET and POST requests etc. just having them in your frontend is fine! If you want to split it out a little more, you can create a <nameOfComponent>Service.ts file that contains all the API routes for a specific component or area of the application and then export them from there to use in the components being rendereded!
RaiRai
RaiRai5mo ago
This makes sense thank you!! I think I’m gonna go with separate files since I’m handling auth and everything have you used next auth with expo before?
DrPorkChop
DrPorkChop5mo ago
I haven’t but I can try my best to help if you’re having any issues!
RaiRai
RaiRai5mo ago
ty! ive used next auth before and its so nice to use as a dev. The expo docs for auth-session seem like they need a bunch of configuration for facebook or google etc. Do you think I should just go with the expo docs?
Want results from more Discord servers?
Add your server