// 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);
Example of creating a user:
curl -i -X POST -d
'{"name": "John Snow", "title": "King of the North"}'
http://example.com/api/v1/users