If my server functions are calling other APIs, should I still use them?
So, I just deployed a landing page using tanstack-start (https://pricesurvey.io) and now I'm going to create a web application. I already have a backend setup in another application, even though tanstack start is a full-stack framework, at the moment my only requirement is to integrate the frontend with this other backend, with this context given, is it necessary/recommended to use server functions? If not, what to use instead?
Price Survey
Price Survey - Pesquisa e Inteligência de Mercado
Visibilidade em pricing para varejo e indústrias: dados confiáveis via crowdsourcing em lojas físicas e e-commerce, até nas regiões mais remotas do Brasil.
5 Replies
magic-amber•3mo ago
you should be able to use server functions to call your other service on your server
i think it's a good idea, because that makes a single clear api (as in interface) for your frontend
you'll be able to change the implementation later and progressively give up the other service seamlessly
noble-goldOP•3mo ago
Even if the applications are in different servers?
magic-amber•3mo ago
i guess it depends on how much you’re able to cache and/or SSR to avoid expensive round trips
noble-goldOP•3mo ago
Yes, this was one of my concerns. By using server functions I'm basically making two requests instead of one? Like
- Without SF: useQuery -> api call -> response
- With SF: useQuery -> tanstack "backend" -> api call -> response
Is this how it works?
magic-amber•3mo ago
yes
depending on what type of application you have, i dont think this is so bad
i would even say it's not that uncommon (at least, ive heard and seen this multiple times; not that repetition always legitimizes... 🙃 )