kore-doc

The kore documentation found under https://docs.kore.io/
Commits | Files | Refs | README | git clone https://git.kore.io/kore-doc.git

routes.md (1329B)



      1 # Configuring routes
      2 
      3 Configuring routes in Kore happens in the Kore configuration inside
      4 of the domain configuration block.
      5 
      6 Routes are evaluated from top to bottom.
      7 Routes can either contain a fixed string of be a regular expression.
      8 
      9 ```
     10 domain * {
     11 	route / {
     12 		handler root_page
     13 	}
     14 
     15 	route /about/ {
     16 		handler about_page
     17 	}
     18 
     19 	route ^.*$ {
     20 		handler redirect
     21 	}
     22 }
     23 ```
     24 
     25 In the example above the configuration specifies 2 fixed routes and one
     26 regex route that captures all the other paths and sends them to some
     27 redirection function.
     28 
     29 # Parameter configuration
     30 
     31 If you wish to receive parameters via a route you **must** define them
     32 in the configuration **and** specify how they should be validated.
     33 
     34 Validation is not optional.
     35 
     36 You define how to validate the parameters inside of the route context.
     37 
     38 ```
     39 # First we must define a validator (in the global config)
     40 validator v_number regex ^[0-9]$
     41 
     42 domain * {
     43 	route / {
     44 		handler root_page
     45 		methos get post
     46 		validate qs:get id v_number
     47 		validate post id v_number
     48 	}
     49 }
     50 ```
     51 
     52 The validate syntax is as follows:
     53 
     54 ```
     55 validate method parameter validator
     56 ```
     57 
     58 Where **method** is the lowercase method (eg: post, get) and optionally
     59 prefixed with **qs:** indicating the query string should be validated with
     60 this parameters.
     61 
     62 If validation for a parameter fails it is filtered out.