NanoFramework 1.4.0
A tiny PHP Framework
Syntax for the route file

Each line of the file represents a rule and is composed in 5 parts:

  • The HTTP method(s)
  • The character :
  • The requested URI
  • The characters ->
  • The target URI

HTTP Methods

The method can be:

  • One of get, post, put, delete
  • A combination of more that one of them separated by commas, for example: get,post
  • The keyword all, equivalent to get,post,put,delete

Requested URI

The requested URI can be any URI, expressed in RegEx. Two placeholders can be used for readability:

  • :segment represents a URI segment (a part between two /)
  • :any represents one or more segments

Parentheses can be used to capture parts of the URI.

Target URI

The target URI must correspond to a Controller. It must have the syntax controller/method/params. If params is missing, no parameters will be sent to the method. If method is missing, index will be used.

Placeholders such as $1, $2, etc. can be used to display the captured parentheses in the RegEx.

Comments

Comments can be added in the file. They start with a # and can either be on their own line or at the end of a line.

Blank lines can also appear in the file.

Valid examples

Here is an example of a valid routes file. Note that the whitespaces is optional and only present to improve readability.

# Homepage
get: / -> /article # this could have been /article/index
# Article pages
get: /(:segment) -> /article/show/$1
get,post: /(:segment)/edit -> /article/edit/$1
delete: /(:segment) -> /article/delete/$1
# Images
get: /uploads/(:any) -> /files/show/$1
# Shortcut
any: /about-me -> /user/show/1