-
Would there be any plans in the future to offer support for RESTful routing?
-
If not anytime "soon", what might be best approach to implement this (where to start)?
Specifically, away we can specify the HTTP METHOD (POST/PUT/UPDATE/DELETE) in the routing rules so the route mapping can be based on that also.
For example, to support resource oriented architecture for creating a RESTful API, we want multiple patterns of /articles to be routed to different controller/actions based on the HTTP METHOD.
Today in Yii, a route rules looks like this:
'rules'=>array(
'pattern1'=>'route1',
'pattern2'=>'route2',
'pattern3'=>'route3',
),
Maybe offer something like (maybe not best approach, but some way to specify the method in rules)
'rules'=>array(
array('pattern1' => 'route1', 'http_method1' => 'METHOD1'),
array('pattern2' => 'route1', 'http_method2' => 'METHOD2'),
),
More concretely:
'rules'=>array(
array('articles' => 'articles/index', 'http_method' => 'GET'),
array('articles' => 'articles/create', 'http_method' => 'POST'),
array('articles/<id:>' => 'articles/update', 'http_method' => 'PUT'),
array('articles' => 'articles/delete', 'http_method' => 'DELETE'),
array('articles/<id:>' => 'articles/show', 'http_method' => 'GET'),
),
We could even make it a convenience through conventions by defining a "resource" in urlManager
such that those combination of patterns/routes/http_method are automatically generated:
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'pattern1'=>'route1',
'pattern2'=>'route2',
'pattern3'=>'route3',
),
'resources' => array('articles'), // would automatically support the routes in concrete example
),