New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider clarifying data fetching page #7854
Comments
Thank you for this comment @Axelgustavschnurer ! I know that @sasoria originally contributed that paragraph (almost a year ago!), so I will ask them if they would be willing to check to see whether anything has changed since that content was correct. Additionally, I think an example using endpoints would be a very helpful addition! Would welcome a PR if someone would like to add one (and, that should help us correct the earlier paragraph). |
Thanks for the issue, I remember that we had some questions about this. I've taken a quick look at this and the correct way of doing the fetch would be: await fetch(new URL("/my-api", Astro.url)); However this will only work for applications that have SSR enabled, so I'm fine with either removing it or writing a seperate sentence about it instead. Perhaps explaining that it's only for SSR and linking to the reference page for Astro.url? |
Thanks for confirming Sergio! So what about something maybe like like:
??? |
I like it. However it will only work on Here's an alternative way of writing it:
|
I reworded the suggestion above a little. Maybe this is easier to read.
|
Love it! |
📚 Subject area/topic
Data Fetching
📋 Page(s) affected (or suggested, for new content)
https://docs.astro.build/en/guides/data-fetching/
📋 Description of content that is out-of-date or incorrect
Data fetching page currently says:
"All Astro components have access to the global fetch() function 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 works as expected for external api's:
Code:
Build yields:
However this does not work when using prebuilt static endpoints or SSR endpoints generated at buildtime:
Code:
Build yields:
As pages are not able to build when using neither statically built endpoints or server side endpoints i believe adding examples showing proper usage of or removing the mention of
Astro.url + "/api"
should be considered. Another issue is thatAstro.url
in itself is an object which cannot be concatenated with any string as is suggested in the documentation.🖥️ Reproduction in StackBlitz (if reporting incorrect content or code samples)
No response
The text was updated successfully, but these errors were encountered: