A route for any method requests to a path. It is answered by a controller (to), a view, a redirect, or the statements inside it (<return value="..." />).
Holds statements.Holds statements in { }. Scripts only. Goes inside <KScript.Routes>Routes or <Group>Group.
AttributeOption
Value
Description
pathrequired
a string
The path, with parameters: /people/. {name?} is optional and {name*} takes the rest of the path.
to
a function: @name
The controller: a <fn> (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.The controller: a fn (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.
view
a string
Answer with this view instead, from the views folder, with the path parameters as variables.
redirect
a string
Answer with a redirect to this address instead.
status
expression
The redirect's status code, 302 by default.
name
a string
A name for the route, for @route('name', ...).
label_key
a string
A translation key for the route's display label.
data
expression
Optional route metadata made from a declared record type.
An ability the model's policy must allow before the controller runs: can: update. It is asked about the record the controller's typed path parameter names, fn update(post: Post). A no answers 403, and a guest the ability turns away is sent to sign in (401 for an API).
where
a string
Rules for the parameters: where: { id: int, slug: slug } (XML: where="id: int, slug: slug"). Rules: number, int, alpha, alnum, slug, uuid or a regular expression.
etag
true or false
true tags GET answers with an ETag (a hash of the body) and answers If-None-Match with 304 Not Modified when the client already has that version.
cache
a string
The Cache-Control header for GET answers: public, max-age=300, or just a number of seconds (300 is public for 5 minutes), private, no-store...
A route for DELETE requests to a path. It is answered by a controller (to), a view, a redirect, or the statements inside it (<return value="..." />).
Holds statements.Holds statements in { }. Scripts only. Goes inside <KScript.Routes>Routes or <Group>Group.
AttributeOption
Value
Description
pathrequired
a string
The path, with parameters: /people/. {name?} is optional and {name*} takes the rest of the path.
to
a function: @name
The controller: a <fn> (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.The controller: a fn (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.
view
a string
Answer with this view instead, from the views folder, with the path parameters as variables.
redirect
a string
Answer with a redirect to this address instead.
status
expression
The redirect's status code, 302 by default.
name
a string
A name for the route, for @route('name', ...).
label_key
a string
A translation key for the route's display label.
data
expression
Optional route metadata made from a declared record type.
An ability the model's policy must allow before the controller runs: can: update. It is asked about the record the controller's typed path parameter names, fn update(post: Post). A no answers 403, and a guest the ability turns away is sent to sign in (401 for an API).
where
a string
Rules for the parameters: where: { id: int, slug: slug } (XML: where="id: int, slug: slug"). Rules: number, int, alpha, alnum, slug, uuid or a regular expression.
etag
true or false
true tags GET answers with an ETag (a hash of the body) and answers If-None-Match with 304 Not Modified when the client already has that version.
cache
a string
The Cache-Control header for GET answers: public, max-age=300, or just a number of seconds (300 is public for 5 minutes), private, no-store...
A route for GET requests to a path. It is answered by a controller (to), a view, a redirect, or the statements inside it (<return value="..." />).
Holds statements.Holds statements in { }. Scripts only. Goes inside <KScript.Routes>Routes or <Group>Group.
AttributeOption
Value
Description
pathrequired
a string
The path, with parameters: /people/. {name?} is optional and {name*} takes the rest of the path.
to
a function: @name
The controller: a <fn> (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.The controller: a fn (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.
view
a string
Answer with this view instead, from the views folder, with the path parameters as variables.
redirect
a string
Answer with a redirect to this address instead.
status
expression
The redirect's status code, 302 by default.
name
a string
A name for the route, for @route('name', ...).
label_key
a string
A translation key for the route's display label.
data
expression
Optional route metadata made from a declared record type.
An ability the model's policy must allow before the controller runs: can: update. It is asked about the record the controller's typed path parameter names, fn update(post: Post). A no answers 403, and a guest the ability turns away is sent to sign in (401 for an API).
where
a string
Rules for the parameters: where: { id: int, slug: slug } (XML: where="id: int, slug: slug"). Rules: number, int, alpha, alnum, slug, uuid or a regular expression.
etag
true or false
true tags GET answers with an ETag (a hash of the body) and answers If-None-Match with 304 Not Modified when the client already has that version.
cache
a string
The Cache-Control header for GET answers: public, max-age=300, or just a number of seconds (300 is public for 5 minutes), private, no-store...
A route for OPTIONS requests to a path. It is answered by a controller (to), a view, a redirect, or the statements inside it (<return value="..." />).
Holds statements.Holds statements in { }. Scripts only. Goes inside <KScript.Routes>Routes or <Group>Group.
AttributeOption
Value
Description
pathrequired
a string
The path, with parameters: /people/. {name?} is optional and {name*} takes the rest of the path.
to
a function: @name
The controller: a <fn> (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.The controller: a fn (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.
view
a string
Answer with this view instead, from the views folder, with the path parameters as variables.
redirect
a string
Answer with a redirect to this address instead.
status
expression
The redirect's status code, 302 by default.
name
a string
A name for the route, for @route('name', ...).
label_key
a string
A translation key for the route's display label.
data
expression
Optional route metadata made from a declared record type.
An ability the model's policy must allow before the controller runs: can: update. It is asked about the record the controller's typed path parameter names, fn update(post: Post). A no answers 403, and a guest the ability turns away is sent to sign in (401 for an API).
where
a string
Rules for the parameters: where: { id: int, slug: slug } (XML: where="id: int, slug: slug"). Rules: number, int, alpha, alnum, slug, uuid or a regular expression.
etag
true or false
true tags GET answers with an ETag (a hash of the body) and answers If-None-Match with 304 Not Modified when the client already has that version.
cache
a string
The Cache-Control header for GET answers: public, max-age=300, or just a number of seconds (300 is public for 5 minutes), private, no-store...
A route for PATCH requests to a path. It is answered by a controller (to), a view, a redirect, or the statements inside it (<return value="..." />).
Holds statements.Holds statements in { }. Scripts only. Goes inside <KScript.Routes>Routes or <Group>Group.
AttributeOption
Value
Description
pathrequired
a string
The path, with parameters: /people/. {name?} is optional and {name*} takes the rest of the path.
to
a function: @name
The controller: a <fn> (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.The controller: a fn (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.
view
a string
Answer with this view instead, from the views folder, with the path parameters as variables.
redirect
a string
Answer with a redirect to this address instead.
status
expression
The redirect's status code, 302 by default.
name
a string
A name for the route, for @route('name', ...).
label_key
a string
A translation key for the route's display label.
data
expression
Optional route metadata made from a declared record type.
An ability the model's policy must allow before the controller runs: can: update. It is asked about the record the controller's typed path parameter names, fn update(post: Post). A no answers 403, and a guest the ability turns away is sent to sign in (401 for an API).
where
a string
Rules for the parameters: where: { id: int, slug: slug } (XML: where="id: int, slug: slug"). Rules: number, int, alpha, alnum, slug, uuid or a regular expression.
etag
true or false
true tags GET answers with an ETag (a hash of the body) and answers If-None-Match with 304 Not Modified when the client already has that version.
cache
a string
The Cache-Control header for GET answers: public, max-age=300, or just a number of seconds (300 is public for 5 minutes), private, no-store...
A route for POST requests to a path. It is answered by a controller (to), a view, a redirect, or the statements inside it (<return value="..." />).
Holds statements.Holds statements in { }. Scripts only. Goes inside <KScript.Routes>Routes or <Group>Group.
AttributeOption
Value
Description
pathrequired
a string
The path, with parameters: /people/. {name?} is optional and {name*} takes the rest of the path.
to
a function: @name
The controller: a <fn> (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.The controller: a fn (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.
view
a string
Answer with this view instead, from the views folder, with the path parameters as variables.
redirect
a string
Answer with a redirect to this address instead.
status
expression
The redirect's status code, 302 by default.
name
a string
A name for the route, for @route('name', ...).
label_key
a string
A translation key for the route's display label.
data
expression
Optional route metadata made from a declared record type.
An ability the model's policy must allow before the controller runs: can: update. It is asked about the record the controller's typed path parameter names, fn update(post: Post). A no answers 403, and a guest the ability turns away is sent to sign in (401 for an API).
where
a string
Rules for the parameters: where: { id: int, slug: slug } (XML: where="id: int, slug: slug"). Rules: number, int, alpha, alnum, slug, uuid or a regular expression.
etag
true or false
true tags GET answers with an ETag (a hash of the body) and answers If-None-Match with 304 Not Modified when the client already has that version.
cache
a string
The Cache-Control header for GET answers: public, max-age=300, or just a number of seconds (300 is public for 5 minutes), private, no-store...
A route for PUT requests to a path. It is answered by a controller (to), a view, a redirect, or the statements inside it (<return value="..." />).
Holds statements.Holds statements in { }. Scripts only. Goes inside <KScript.Routes>Routes or <Group>Group.
AttributeOption
Value
Description
pathrequired
a string
The path, with parameters: /people/. {name?} is optional and {name*} takes the rest of the path.
to
a function: @name
The controller: a <fn> (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.The controller: a fn (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.
view
a string
Answer with this view instead, from the views folder, with the path parameters as variables.
redirect
a string
Answer with a redirect to this address instead.
status
expression
The redirect's status code, 302 by default.
name
a string
A name for the route, for @route('name', ...).
label_key
a string
A translation key for the route's display label.
data
expression
Optional route metadata made from a declared record type.
An ability the model's policy must allow before the controller runs: can: update. It is asked about the record the controller's typed path parameter names, fn update(post: Post). A no answers 403, and a guest the ability turns away is sent to sign in (401 for an API).
where
a string
Rules for the parameters: where: { id: int, slug: slug } (XML: where="id: int, slug: slug"). Rules: number, int, alpha, alnum, slug, uuid or a regular expression.
etag
true or false
true tags GET answers with an ETag (a hash of the body) and answers If-None-Match with 304 Not Modified when the client already has that version.
cache
a string
The Cache-Control header for GET answers: public, max-age=300, or just a number of seconds (300 is public for 5 minutes), private, no-store...
The usual routes of a JSON resource, answered by the functions a controller script exports: index (GET path), store (POST path), show (GET path/), update (PUT and PATCH path/) and destroy (DELETE path/). Functions the controller doesn't have get no route.
Self-closing.A statement on its own. Scripts only. Goes inside <KScript.Routes>Routes or <Group>Group.
AttributeOption
Value
Description
pathrequired
a string
The resource's path, such as /people.
torequired
a string
The controller: the name a script is imported as (<import path="..." as="people" />).
only
index | store | show | update | destroy
Only these actions: [index, show].
except
index | store | show | update | destroy
All actions but these: [destroy].
name
a string
The route name prefix (people gives people.index, people.show...). The default is the controller's name.
param
a string
The name of the path parameter, id by default.
model
a string
The model the resource is about. Each action then asks the model's policy first: show asks read, store asks create, update asks update and destroy asks delete. index isn't asked, since it has no one record.
Holds statements.Holds statements in { }. Scripts only. Goes inside <KScript.Routes>Routes or <Group>Group.
AttributeOption
Value
Description
pathrequired
a string
The path, with parameters: /people/. {name?} is optional and {name*} takes the rest of the path.
methodsrequired
get | post | put | patch | delete | options | head
The HTTP methods: [get, post].
to
a function: @name
The controller: a <fn> (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.The controller: a fn (@show) or a function of an imported script (@people.show); in XML, to="people.show". Its parameters are filled by name: path parameters, request, json, query, form, input, headers.
view
a string
Answer with this view instead, from the views folder, with the path parameters as variables.
redirect
a string
Answer with a redirect to this address instead.
status
expression
The redirect's status code, 302 by default.
name
a string
A name for the route, for @route('name', ...).
label_key
a string
A translation key for the route's display label.
data
expression
Optional route metadata made from a declared record type.
An ability the model's policy must allow before the controller runs: can: update. It is asked about the record the controller's typed path parameter names, fn update(post: Post). A no answers 403, and a guest the ability turns away is sent to sign in (401 for an API).
where
a string
Rules for the parameters: where: { id: int, slug: slug } (XML: where="id: int, slug: slug"). Rules: number, int, alpha, alnum, slug, uuid or a regular expression.
etag
true or false
true tags GET answers with an ETag (a hash of the body) and answers If-None-Match with 304 Not Modified when the client already has that version.
cache
a string
The Cache-Control header for GET answers: public, max-age=300, or just a number of seconds (300 is public for 5 minutes), private, no-store...
A route file: maps HTTP methods and paths to controllers, views and redirects. kscript serve loads routes.ks.xml (or routes.kscript) and api.ks.xml (under /api, with JSON errors). Its <import>, <fn> and <let> children run on every request before the route is matched.A route file: maps HTTP methods and paths to controllers, views and redirects. kscript serve loads routes.ks.xml (or routes.kscript) and api.ks.xml (under /api, with JSON errors). Its import, fn and $name = value children run on every request before the route is matched.
Holds statements.Holds statements in { }. Scripts only.
AttributeOption
Value
Description
prefix
a string
A path in front of every route in the file, such as /v1.
Middleware for every route in the file, comma separated: built-ins (log, cors, auth, throttle:30) or <fn>s taking ($request, $next).Middleware for every route in the file, comma separated: built-ins (log, cors, auth, throttle:30) or fns taking ($request, $next).
name
a string
Put in front of every route name, such as admin.
api
true or false
true: errors and missing routes are answered with JSON (api.* files are API files already).
Tags the answer with an ETag made from a value (such as a record's version or updated time). When the request's If-None-Match already has it, the request stops here with 304 Not Modified, so the rest of the controller doesn't run.
A redirect to the page the request came from (its Referer), the usual answer to a form that didn't validate. Only a page on this site counts: a Referer from anywhere else, or none, goes to default (/ when left out).
A response with a status code and headers. A map or list body is sent as JSON, text as HTML, and a base64 value as raw bytes. Set type to override the default Content-Type.
Returns the URL for a named route. Pass the route name as nonempty text and supply the values for its path parameters. For example, @route('people.show', id: 3) returns /people/3. Extra named values become query parameters.
A link only this app could have made, for unsubscribe, verify and download links: a route's name with its parameters (as @route() takes them), or a path, with a signature added. expires: makes it stop working after that long, such as 7d. Check it with the signed middleware or $request.has_valid_signature; changing any part of the link breaks it.
Renders a page from the views folder (or the site folder) with its layout, giving it the named values as variables: @view('people/show.html', person: $p). The extension may be left off. status: sets the answer's status code: @view('auth/login', error: $message, status: 422).