用于多模块应用程序的 RESTful API 路由

// Define new router group
$api = new \Phalcon\Mvc\Router\Group([
    'module' => 'api',
]);
$api->setPrefix('/api/v1');

// API routes (Maps to Cotnroller::Action)
$api->addGet('/users', 'Users::index');
$api->addGet('/users/search/{query}', 'Users::search');
$api->addGet('/users/{id:[0-9]+}', 'Users::fetch');
$api->addPost('/users', 'Users::add');
$api->addPut('/users/{id:[0-9]+}', 'Users::edit');
$api->addDelete('/users/{id:[0-9]+}', 'Users::delete'); 

// Add API routes to main router
$router->mount($api);

创建用户的示例:

curl -i -X POST -d 
    '{"name": "John Snow", "title": "King of the North"}' 
    http://example.com/api/v1/users