From 1f3c047522c85e3978c8b1538059e3345a1a0e7e Mon Sep 17 00:00:00 2001 From: "Sergio A. Arevalo Soria" Date: Tue, 25 Jul 2023 13:26:58 +0200 Subject: [PATCH] Document url constraint in data fetching (#3677) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Elian ☕️ Co-authored-by: Sarah Rainsberger --- src/content/docs/en/guides/data-fetching.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/content/docs/en/guides/data-fetching.mdx b/src/content/docs/en/guides/data-fetching.mdx index 0dbf2c5468d3e..e27ca461448de 100644 --- a/src/content/docs/en/guides/data-fetching.mdx +++ b/src/content/docs/en/guides/data-fetching.mdx @@ -8,7 +8,9 @@ i18nReady: true ## `fetch()` in Astro -All [Astro components](/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. If [SSR](/en/guides/server-side-rendering/) mode is enabled, any fetch calls will be executed at runtime. +All [Astro components](/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 using the full URL (e.g. https://example.com/api or `Astro.url + "/api"`). + +This fetch call will be executed at build time, and the data will be available to the component template for generating dynamic HTML. If [SSR](/en/guides/server-side-rendering/) mode is enabled, any fetch calls will be executed at runtime. 💡 Take advantage of [**top-level await**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#top_level_await) inside of your Astro component script.