const classafBedSheet::Route

sys::Obj
  afBedSheet::Route

Matches uri paths to request handler methods, converting any remaining path segments into method arguments. Use * to capture (non-greedy) method arguments, ** to capture all remaining path segments and *** to capture the remaining url. Examples:

glob pattern     uri             arguments
--------------------------------------------
/user/*      --> /user/       => null
/user/*      --> /user/42     => "42"
/user/*      --> /user/42/    => no match
/user/*      --> /user/42/dee => no match

/user/*/*    --> /user/       => no match
/user/*/*    --> /user/42     => no match
/user/*/*    --> /user/42/    => "42", null
/user/*/*    --> /user/42/dee => "42", "dee"

/user/**     --> /user/       => null
/user/**     --> /user/42     => "42"
/user/**     --> /user/42/    => "42"
/user/**     --> /user/42/dee => "42", "dee"

/user/***    --> /user/       => null
/user/***    --> /user/42     => "42"
/user/***    --> /user/42/    => "42/"
/user/***    --> /user/42/dee => "42/dee"

The argument list is then matched to the method parameters, taking into account nullable types and default values. Examples:

method params             arguments       match
--------------------------------------------------
Str a, Str b         -->               => no match  
Str a, Str b         -->  null         => no match
Str a, Str b         -->  null,  null  => no match 
Str a, Str b         --> "wot", "ever" => match

Str? a, Str? b       -->               => no match
Str? a, Str? b       -->  null         => no match
Str? a, Str? b       -->  null,  null  => match
Str? a, Str? b       --> "wot", "ever" => match

Str? a, Str? b := "" -->               => no match
Str? a, Str? b := "" -->  null         => match
Str? a, Str? b := "" -->  null,  null  => match
Str? a, Str? b := "" --> "wot", "ever" => match

Str? a, Str b := ""  -->               => no match
Str? a, Str b := ""  -->  null         => match
Str? a, Str b := ""  -->  null,  null  => no match
Str? a, Str b := ""  --> "wot", "ever" => match

Method parameters can be any Obj (and not just Str) as they are converted using the ValueEncoder service.

TIP: Contribute ValueEncoders to convert path segments into Entities. BedSheet will then call handlers with real Entities, not just str IDs!

Parameters of type Str[] are capture all parameters and match the remaining uri (split on /).

Request uri's (for matching purposes) are treated as case-insensitive.

Use ? to optional match the last character. Use to optionally match a trailing slash. e.g.

glob         uri
-----------------------------
/index/? --> /index  => match
/index/? --> /index/ => match
vs
/index/  --> /index  => no match
/index   --> /index/ => no match

If a handler class is a service, it is obtained from the IoC registry, otherwise it is autobuilt. If the class is const, the instance is cached for future use.

handler

Source

const Method handler

Method handler for this route.

httpMethod

Source

const Str httpMethod

HTTP method used for this route

makeFromGlob

Source

new makeFromGlob(Uri glob, Method handler, Str httpMethod := "GET")

Make a Route that matches on the given glob pattern.

glob must start with a slash "/"

httpMethod may be a glob. Example, use "*" to match all methods.

makeFromRegex

Source

new makeFromRegex(Regex uriRegex, Method handler, Str httpMethod := "GET", Bool matchRemaining := false)

For hardcore users; make a Route from a regex. Capture groups are used to match arguments. Example:

Route(Regex<|(?i)^\/index\/(.*?)$|>, #foo, "GET", true) -> Route(`/index/**`)

Set matchRemaining to true to have the last capture group mimic the glob ** operator, splitting on "/" to match all remaining segments.

routeRegex

Source

const Regex routeRegex

The uri regex this route matches.

toStr

Source

virtual override Str toStr()