-
-
Notifications
You must be signed in to change notification settings - Fork 2k
pages ignore HTTP method -- is this desirable? #1175
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
Comments
Yeah, I think pages themselves should only respond to |
That seems reasonable but it does prevent you from easily using the classic |
It doesn't — |
Ah, I guess you were responding to this:
Now that I think about it, I think we looked into this before and decided that the current behaviour does make sense, because if pages did only respond to The weirdness that results is that you can also |
Would it be possible to restrict page handling of non-GET requests to fallthrough cases? I guess there isn't currently a way because fallthrough is purely negative (lack of a response) and there isn't really a way to detect whether an endpoint did something and wants/expects fallthrough. However a partial version of this might be possible, where pages that lack shadow endpoints only take GET. |
It veers slightly into magical territory. I think I'd prefer that we just document that pages will respond to any method, and if you want to handle non-GETs sensibly then you need a shadowing endpoint with a fallthrough |
Sorry to tack a question on to this but... when you do fall through is it possible to access data that was created in the endpoint? How about the original request body? My use case example being an endpoint that processes a form submission (POST), checks for validation errors and, if there are any, falls-through to re-show the form with the errors displayed (and originally posted values) so the user can try again. i.e. the "the classic " approach mentioned above. |
Closing in favour of #3532 |
I recently noticed that SvelteKit matches pages on path alone and ignores the HTTP method. For example, if you create
routes/foo.svelte
, you can GET, POST, PUT, or DELETE to/foo
and the rendered response is the same. This may be intentional, but it's pretty surprising, so it should at least be documented.One complication of the current implementation is that the HTTP method and request body (for example POSTed form data) are not made visible to
load
. They're available inhandle
, so someone could pass them along viacontext
pretty easily if they wanted to. On the other hand, if someone wants to globally restrict pages to GET only (which seems sensible for many use cases), I don't see an easy way to do that currently, becausehandle
doesn't know if it's going to render a page or an endpoint.I'm creating this issue to bring attention to this (unintentional?) design feature and start more discussion about it. I don't really have a strong opinion on how to address it other than to document it better. And it would be nice if
load
had more visibility into the request without needing custom code inhandle
. (It would also be possible to fix things by only matching pages on GET, but that's probably unnecessarily restrictive.)The text was updated successfully, but these errors were encountered: