Improve docs on endpoints#4445
Improve docs on endpoints#4445stephane-vanraes wants to merge 0 commit intosveltejs:masterfrom stephane-vanraes:master
Conversation
|
documentation/docs/01-routing.md
Outdated
| ### Endpoints | ||
|
|
||
| Endpoints are modules written in `.js` (or `.ts`) files that export [request handler](/docs/types#sveltejs-kit-requesthandler) functions corresponding to HTTP methods. Their job is to make it possible to read and write data that is only available on the server (for example in a database, or on the filesystem). | ||
| Endpoints are modules written in `.js` (or `.ts`) files that export [request handler](/docs/types#sveltejs-kit-requesthandler) functions corresponding to HTTP methods, which take a [RequestEvent](/docs/types#additional-types-requestevent) as input and return a [RequestHandlerOutput](/docs/types#sveltejs-kit-requesthandleroutput). Their job is to make it possible to read and write data that is only available on the server (for example in a database, or on the filesystem). |
There was a problem hiding this comment.
| Endpoints are modules written in `.js` (or `.ts`) files that export [request handler](/docs/types#sveltejs-kit-requesthandler) functions corresponding to HTTP methods, which take a [RequestEvent](/docs/types#additional-types-requestevent) as input and return a [RequestHandlerOutput](/docs/types#sveltejs-kit-requesthandleroutput). Their job is to make it possible to read and write data that is only available on the server (for example in a database, or on the filesystem). | |
| Endpoints are modules written in `.js` (or `.ts`) files that export [request handler](/docs/types#sveltejs-kit-requesthandler) functions corresponding to HTTP methods, which take a [`RequestEvent`](/docs/types#additional-types-requestevent) as input and return [`RequestHandlerOutput`](/docs/types#sveltejs-kit-requesthandleroutput). Their job is to make it possible to read and write data that is only available on the server (for example in a database, or on the filesystem). |
That said, I'm not sure whether this change is necessary, because if you click "request handler", you're brought to its type, where you can see what it accepts and returns.
|
Addressing @Conduitry's question above, I think this is a reasonable change for a couple reasons:
Frankly, our display of types that use a lot of generics is not very good. We could customize this to be easier to read by generating the docs ourselves (like in #4005), but it would be quite a bit of work whereas this is a pretty easy change to implement If there's one other place I think it might be worth linking directly to the input/output it would be https://kit.svelte.dev/docs/loading since it's the most used part of SvelteKit and most of the points above apply there as well. I updated the PR to update that page as well so that whatever we decide here we're doing things consistently. I don't think I'd probably do it beyond that |
|
I think the main concern with legibility is that in the current form the signatures are hard to read for those not used to TypeScript. is still fairly straightfoward and doable for non-TS developers. But the entire construction with the generics and extends could very well be a completely different language (which technically it is). |
|
The types documentation absolutely needs some love, especially the public types. Most of the types are just code blocks of its type signature without any description, and I think we can mitigate a lot of these problems by just having some explanation about the code blocks. Explaining the type would also reduce the burden of having to manually update the links in case the name changes because they are already automatically linked in the code blocks when generated. This feels like it belongs in the Anyone using these types (with TS) needs to understand how the whole |
|
Agree that the type is cryptic, but also agree that the changes don't really belong anywhere else. What about #4475 as an alternative? |
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpx changesetand following the prompts. All changesets should bepatchuntil SvelteKit 1.0This PR includes a small improvement to the docs regarding endpoints, currently it is not easy to figure out what the input parameters to the functions are as it involves a lot of clicking around. The change aims to have the RequestEvent and RequestOutputHandler types directly linked from the text instead.