Restful – a resource route ignored

Member | 12

I use Drahak/Restful to build a REST/Web API. I have following routes defined.

$router[] = new Route('<presenter>/<action>[/<id>]', 'Homepage:default');
$router[] = new ResourceRoute('api/v1/groups/<groupID>/accounts', array(
    'presenter' => 'Api',
    'action' => array(
        ResourceRoute::POST => 'createGroupAccount',
), ResourceRoute::POST);
$router[] = new ResourceRoute('api/v1/trips', array(
    'presenter' => 'Api',
    'action' => array(
        ResourceRoute::POST => 'createTrip',
), ResourceRoute::POST);

Both ApiPresenter#actionCreateGroupAccount(int) and ApiPresenter#actionCreateTrip() exist in given presenter. When sending valid request POST /api/v1/groups/1/accounts, the action handler is executed and HTTP 201 Created is returned. However, when I request POST /api/v1/trips with valid input data, the action handler is not executed and HTTP 204 No Content is returned. Drahak Restufl Panel shows both routes existing in Nette.

Any suggestions where to look?

Last edited by jspetrak (2015-01-09 15:53)



The solution was to reorder the route list. The general route should be the last one.

3 years ago