KScript docs
EN

Routes and APIs

Named routes

name: gives a route a name, so you can make its address with @route() instead of writing the path out. Names must be unique:

<!-- routes.kscript -->
<KScript.Routes>
  <import path="controllers/people.kscript" as="people" />

  <Get path="/people/{id}" to="people.page" name="people.page" />
</KScript.Routes>
// routes.kscript
import KScript.Http
import "controllers/people.kscript" as people

Routes {
  Get(path: /people/{id}, to: @people.page, name: 'people.page')
}

@route('people.page', id: 3) then gives /people/3. A controller can read the name of the route that matched it from $request.route.