-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Bring back support for content negotiation (allow +page.svelte & +server.ts to co-exist) #5896
Comments
I'm not sure the proposed logic is quite right — there's nothing special about Pending the outcome of #5875, what happens if |
Yes, the negotiation part is more about the request not coming from a regular web browser page request, so only being limited to a particular type. I used The overlap between Taking that into account, I would prefer that |
Just learned from @s3812497 in discussion that we can't do GET My use case: I have bigger content properties but send only smaller, requested chunks via REST. With the initial pageload the user gets the first part and then, within the client the user can request further parts without the need to reload the page. Both use the exact same API and DB call. It'd be nice to just use the same Why not Not sure if I miss something and/or this would align well with #5875 |
* [feat] allow +server.js files next to +page files Closes #5896 * Update packages/kit/src/runtime/server/endpoint.js Co-authored-by: Rich Harris <richard.a.harris@gmail.com> * simplify rules and document them * adjust builder type * Update documentation/docs/06-form-actions.md Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * link * remove unused type * move docs to +server.js section Co-authored-by: Rich Harris <richard.a.harris@gmail.com> Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> Co-authored-by: Rich Harris <hello@rich-harris.dev>
Describe the problem
Previous versions of SvelteKit supported content negotiation where a route could serve HTML to browsers or JSON data if an
accept
header was used for a data request (as well as supporting data being posted to the same route).Existing sites may already use this, it's been part of HTTP since forever. You might want to replace such a site with SvelteKit (or previously relied on SvelteKit supporting this) but changing the existing URL structure would be problematic and impactful (other systems using endpoints, pages already indexed and publicized etc...)
I think a router should be flexible enough to support existing URL structures, even if they are not the favoured default for the framework.
Describe the proposed solution
Support the
accept
header in the routing and allowapplication/json
requests to an endpoint at the same route. Pages should only be concerned with GET requests with noaccept
header (or one for html content).Alternatives considered
Adding a load function to
+page.server.ts
allows a GET request for data, but makes it difficult to control the response and would limit things to JSON (maybe you want CSV, PDF, or XML). It also appears limited in terms of what control you have over the response (http headers etc...) and still leaves you unable to use other HTTP methods.Update: it appears that I should be treating
load
as GET and the other methods are supported. However they are inconsistent in terms of signature and what response is returned.Importance
i cannot use SvelteKit without it
Additional Information
No response
The text was updated successfully, but these errors were encountered: