#Middleware as central point for API calls (GET)
5 messages · Page 1 of 1 (latest)
Hmm, I don't know enough to give you a confident answer yet. The extracts provided do not contain specific information about using fetch() in Astro's middleware. However, they do provide information on how to use fetch() in Astro components and framework components.
In Astro components, all data is fetched when a component is rendered. Your deployed Astro site will fetch data once, at build time. In dev, you will see data fetches on component refreshes. If you need to re-fetch data multiple times client-side, use a framework component (https://docs.astro.build/en/core-concepts/framework-components/) or a client-side script (https://docs.astro.build/en/guides/client-side-scripts/) in an Astro component.
Astro can also use fetch() to query a GraphQL server with any valid GraphQL query. All Astro components (https://docs.astro.build/en/core-concepts/astro-components/) have access to the global fetch() function (https://developer.mozilla.org/en-US/docs/Web/API/fetch) in their component script to make HTTP requests to APIs. This fetch call will be executed at build time, and the data will be available to the component template for generating dynamic HTML.
For more detailed information, you might want to check the Astro documentation on data fetching (https://docs.astro.build/en/guides/data-fetching).
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@static heath kapa.ai is still learning and improving, please let us how it did by reacting below
Let me check the knowledge base for you. One moment! :books: