Issues

ZF-11327: Improvement for Zend_Rest_Route

Description

Today, developing the API (that is similar to Facebook Graph API) for a personal project, I ran into a limitation of the routes taken by Zend_Rest_Route. The limitation is that if I access a url like that: http://example.com/module/controller/…

The id becomes a parameter with value resource, and that's not what I want, and I also guess it's not what other people want, therefore, with the modification that I made, the behaviors possible for the Zend_Rest_Route increases, and is as follows:

{quote} ||Method||URI||Module_Controller::action Default Behavior: |GET|/api/users/|Api_UsersController::indexAction() |GET|/api/users/:id|Api_UsersController::getAction() |POST|/api/users|Api_UsersController::postAction() |PUT|/api/users/:id|Api_UsersController::putAction() |DELETE|/api/users/:id|Api_UsersController::deleteAction() |POST|/api/users/:id?_method=PUT|Api_UsersController::putAction() |POST|/api/users/:id?_method=DELETE|Api_UsersController::deleteAction()

What I've added: |METHOD|/api/users/:id/:resource|Api_UsersController::methodAction() |METHOD|/api/users/:id/:resource/:subresource|Api_UsersController::methodAction() {quote}


elseif (($pathElementCount == 3 || $pathElementCount == 2) && !isset($params['id'])){
    $params['id'] = $path[0];
    $params['resource'] = $path[1]; unset($path[1]);
    if($path[2]){
        $params['subResource'] = $path[2]; unset($path[2]);
    }
}

I hope it is useful to someone, I do not know if what I did is totally correct, but the way it was, I could not get a request like this in my API: http://www.mysite.com/api/users/12345/friends

Comments

In my ZF apps I would have put the "User 12345's friends" resource at:

http://mysite.com/api/friends/index/user/12345

Which would go to FriendsController::indexAction() with user=>12345.

Sub-resource url's are a great idea, though, and I think we should try to implement them in Zend_Rest 2.0 with ZF 2.0 orm.

Yep, but I did not want this index in the url. :)

Sure. I'm basically in a holding pattern on the Zend_Rest stuff until ZF 2.0 MVC is released. So, I'll probably just leave this issue here for triage post-2.0.

without tvil Nike Skateboarding is http://www.nikeshoxsko.biz classic silhuetten get a Woodgrain makeover with this Quickstrike utgivelsen surface on skate butikker this http://www.nikeshoxsko.biz month. Den popular Stefan Janoski pro-Modellen has a tonal brun Øvre with skinn detaljering on the Indre liner, Varme and Blonder.