Routes

Components on the server — design

Status: implemented are markup as HTML, components of the server, their results, Response going up, Content<T>, component values with a result, decorators with guards, wrappers that take the body and the request context, routes, and rooklang/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 and rooklang/server remain 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.

route of rooklang/server ties a path to a page. The parameters of the path are the properties of the page, and the compiler checks them against each other:

import { route, Route, reply } from "rooklang/server"

comp UserPage(id string) { ... }

const ROUTES Route<Html | Response>[] = [
    route("/", Home),
    route("/users/:id", UserPage),
    route("/users/:uid/posts", Posts),   // error: Posts has no property "uid"
]

comp Router(routes Route<Html | Response>[]) {
    for each in routes {
        const Page = each.match(@session.url.pathname)
        if Page != null {
            return <Page />
        }
    }
    return reply(<NotFound />, { status: 404 })
}

Markdown source on GitHub