I am developing an App which consists of a NextJS
frontend and a Rails API
backend.
There is this /api
route from NextJS where I can put "server side code".
Should I use this feature by sending my frontend requests first to that /api
endpoint and then to the Rails API endpoint or is "ok" to directly send the requests to the Rails API endpoint?
For me that looks a bit like a "jump around the corner".
Are there true benefits using the NextJS frontend -> NextJS API -> Rails API
approach?
From next js docs:
Use Cases
For new projects, you can build your entire API with API Routes. If you have an existing API, you do not need to forward calls to the API through an API Route. Some other use cases for API
Routes are:
- Masking the URL of an external service (e.g. /api/secret instead of https://company.com/secret-url)
- Using Environment Variables on the server to securely access external services. https://nextjs.org/docs/api-routes/introduction#use-cases