Skip to content
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

Note static endpoint can return a response object #1961

Closed
wants to merge 1 commit into from

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Oct 31, 2022

What kind of changes does this PR include?

  • New or updated content

Description

Based on withastro/astro#5258, clarify that you can return a response object from a static endpoint as long as it's a successful response.

@netlify
Copy link

netlify bot commented Oct 31, 2022

Deploy Preview for astro-docs-2 ready!

Name Link
🔨 Latest commit f111ea7
🔍 Latest deploy log https://app.netlify.com/sites/astro-docs-2/deploys/635fd712e66a7900077e7311
😎 Deploy Preview https://deploy-preview-1961--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@Jutanium Jutanium added the merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!) label Oct 31, 2022
@sarah11918 sarah11918 added hacktoberfest-accepted Mark a PR as accepted to contribute towards Hacktoberfest improve documentation Enhance existing documentation (e.g. add an example, improve description) labels Oct 31, 2022
Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m wondering if we want to document this? I understand supporting it for consistency, but if I understand correctly you can’t use any of the features of Response really, right? Headers etc. aren’t supported. Are there any circumstances where returning a Response would be preferable to { body: '...' }?

@bluwy
Copy link
Member Author

bluwy commented Oct 31, 2022

Yeah there's not much features you can use with Response now other than user preference. I can also see not documenting this and have the Astro errors cover it too, which I'm also fine with! Right now it's here to only document the possibility, but happy to close this if you prefer too.

@delucis
Copy link
Member

delucis commented Oct 31, 2022

I’d like another opinion from @Jutanium or @sarah11918 before I stomp on your PR! 😅

But I definitely think it’s OK to merge the Astro feature without this PR merged yet and we can take a bit more time to decide how best to document this.

@delucis delucis added the should this be documented? Need to figure out whether this is something to add to documentation or not label Oct 31, 2022
@Jutanium
Copy link
Contributor

I discovered when first working on this guide that it worked in dev and not build, so thanks @bluwy for fixing that! In terms of docs, I like first introducing the a full-fledged Response in the SSR section, where it fully works. We don't want to imply that statusText or headers work in SSG mode, and introducing it there with those caveats begs the question of why you'd use it at all.

The flip side is that someone might try to use it in SSG mode, notice that it partially works, and then get confused when most of it gets ignored. In the spirit of "don't include code samples that we don't want copied", we could replace the code sample with a note or caution:

:::caution
You can return a Response object, but it must return a successful status code. The response body will be built as the endpoint, but other properties (like header and statusText) will be ignored.
:::

I'm also happy to not include it at all.

@bluwy
Copy link
Member Author

bluwy commented Nov 1, 2022

Thanks for the comments @Jutanium. I think it sounds better to not document this until we have better support for it. I agree with all the points you mentioned! Closing this one for now.

@bluwy bluwy closed this Nov 1, 2022
@bluwy bluwy deleted the endpoint-response branch November 1, 2022 06:31
@sarah11918 sarah11918 added the minor-release For the next minor release; in the milestone, "merge queue" when approved by Sarah! label Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Mark a PR as accepted to contribute towards Hacktoberfest improve documentation Enhance existing documentation (e.g. add an example, improve description) merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!) minor-release For the next minor release; in the milestone, "merge queue" when approved by Sarah! should this be documented? Need to figure out whether this is something to add to documentation or not
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants