#multiple api calls

1 messages · Page 1 of 1 (latest)

brazen shoreBOT
#

Hi @flat shale. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the extracts, it's recommended to handle multiple API calls on the server side whenever possible. This approach has several benefits:

  • It allows direct access to backend data resources like databases.
  • It keeps your application more secure by preventing sensitive information, such as access tokens and API keys, from being exposed to the client.
  • It reduces both the back-and-forth communication between client and server, as well as the work on the main thread on the client.
  • It allows you to perform multiple data fetches with a single round-trip instead of multiple individual requests on the client.
  • It reduces client-server waterfalls.
  • Depending on your region, data fetching can also happen closer to your data source, reducing latency and improving performance.

You can fetch data on the server using Server Components, Route Handlers, and Server Actions. For handling form submissions and data mutations, Next.js provides a powerful way to use API Routes. In the near future, Next.js will recommend incrementally adopting the App Router and using Server Actions for handling form submissions and data mutations. Server Actions allow you to define asynchronous server functions that can be called directly from your components, without needing to manually create an API Route.

For more details, you can refer to the Next.js documentation on Data Fetching Patterns (https://nextjs.org/docs/app/building-your-application/data-fetching/patterns) and Forms and Mutations (https://nextjs.org/docs/app/building-your-application/data-fetching/forms-and-mutations).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: