These rules are helpful for anyone looking for a simple, pre-configured RESTful routing scheme. (This would go in your UrlManager::$rules configuration.) Save yourself some time and pick these up, or reply with suggestions for improvements.
See the code comment below for details.
Edit: Changed to a nested-module based format to improve versioning, plus extracts the
<?php
/**
* API Routing Rules
*
* Supports three endpoint styles:
* - Collection: /foos
* - Item: /foos/{fooId}
* - Related Collection: /food/{fooId}/bars
*
* Detect file extension:
* - /foos.json => ?returnType=json
* - /bars.xml => ?returnType=xml
*
* Require version #:
* - /api/v1/foobars.xml => ?apiVersion=v1&returnType=xml
*
* For versioning you're probably best off creating an ApiModule, with sub-modules for each version, e.g. api.modules.V1Module.
**/
$fileExt = 'json|xml';
return array(
array(
'api/<apiVersion>/<controller>/viewResource',
'pattern' =>'api/<apiVersion:v\d+>/<controller:\w+>/<id:\d+>\.?<returnType:('.$fileExt.')?>',
'verb' =>'GET',
),
array(
'api/<apiVersion>/<controller>/viewRelatedCollection',
'pattern' =>'api/<apiVersion:v\d+>/<controller:\w+>/<id:\d+>/<relationName:\w+>\.?<returnType:('.$fileExt.')?>',
'verb' =>'GET',
),
array(
'api/<apiVersion>/<controller>/deleteResource',
'pattern' =>'api/<apiVersion:v\d+>/<controller:\w+>/<id:\d+>\.?<returnType:('.$fileExt.')?>',
'verb' =>'DELETE',
),
array(
'api/<apiVersion>/<controller>/updateResource',
'pattern' =>'api/<apiVersion:v\d+>/<controller:\w+>/<id:\d+>\.?<returnType:('.$fileExt.')?>',
'verb' =>'PUT,POST',
),
array(
'api/<apiVersion>/<controller>/viewCollection',
'pattern' =>'api/<apiVersion:v\d+>/<controller:\w+>\.?<returnType:('.$fileExt.')?>',
'verb' =>'GET',
),
array(
'api/<apiVersion>/<controller>/createResource',
'pattern' =>'api/<apiVersion:v\d+>/<controller:\w+>\.?<returnType:('.$fileExt.')?>',
'verb' =>'POST',
),
array(
'api/<apiVersion>/<controller>/updateCollection',
'pattern' =>'api/<apiVersion:v\d+>/<controller:\w+>\.?<returnType:('.$fileExt.')?>',
'verb' =>'PUT',
),
array(
'api/<apiVersion>/<controller>/deleteCollection',
'pattern' =>'api/<apiVersion:v\d+>/<controller:\w+>\.?<returnType:('.$fileExt.')?>',
'verb' =>'DELETE',
),
);