Decisions
Components on the server — design
Status: implemented are markup as HTML, components of the server, their results,
Responsegoing up,Content<T>, component values with a result, decorators with guards, wrappers that take the body and the request context, routes, androoklang/server; the server of the site,site/server/main.rk, is written with them, and the guide has a section on them. The decisions are collected at the end of the document, together with what is not decided yet. Server markup, components androoklang/serverremain experimental in 1.x and may change between releases.
This document builds on components.md: components, decorators, context, components as values. It describes only what is different on the server.
- The mode is a setting of the package,
"rook": { "markup": "html" }, not a keyword or a name of a file: a file is either for the browser or for the server, and the setting already finds its package. - A component of the server returns any value, inferred or written after the properties: an API and pages are the same tree.
- A
Responseamong children goes up and becomes the answer, so a guard can stand at any depth without passing anything up by hand. - Children are lazy,
Content<T>, and a wrapper is generic: a middleware does not run what it does not let through, and its type is that of what it wraps. - Context is a decorator of a component above, available through its public members: typed, one instance per request, and no new concept besides what decorators are.
- A guard is an early
returnin the body of a decorator. - The entry is
serve(App)andhandler(App)ofrooklang/server, on the web standardRequestandResponse, so one server runs in Node, Bun, Deno and Workers. - An error boundary is a wrapper that takes
Content<T>, not a decorator of the language: the wrapper gets the body to run, and@fallbackis a few lines of Rook. - Routes are
route("/users/:id", UserPage), a function whose literal path the compiler checks against the properties of the page; the router stays Rook code.