pages ignore HTTP method -- is this desirable?
See original GitHub issueI 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 in handle
, so someone could pass them along via context
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, because handle
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 in handle
. (It would also be possible to fix things by only matching pages on GET, but that’s probably unnecessarily restrictive.)
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
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
@goynang Take a look at #1711.