Lazy Routes learned from Sinatra Routes!

The context of route callback handler is the called. Commonly, it is the \Sloths\Application\Application. So every properties, methods of the context is available within the callback handler.

Routes are matched in the order they are defined. The first route that matches the request is invoked unless you call pass() within the route callback, the process will be matching the next route.

Route patterns can be static pattern:


Or includes named parameters:


Or named parameters with double colon:

Named parameters with double colon only matches the numeric value.

Or Includes wildcard parameters:


Or With Regular Expressions: (Regex pattern should start with # character)


Route patterns may have optional parameters:

Access to request parameters:

Return Values

Most commonly, this is a string. But other values are also accepted.

The return values will be send to response body. It mean if return values is an array or object, the response object will be send it as json string and the content type header is application/json.

Simple CRUD Routes

application\routes\posts.php


comments powered by Disqus