Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Creating restful APIs #17

Closed
yaworsw opened this issue Oct 2, 2013 · 0 comments
Closed

Creating restful APIs #17

yaworsw opened this issue Oct 2, 2013 · 0 comments

Comments

@yaworsw
Copy link
Contributor

yaworsw commented Oct 2, 2013

To create a restful API for posts you might think this would do it

$app->addRoutes(array(
    '/posts'      => array('Posts:index',  'get'),
    '/posts/:id'  => array('Posts:show',   'get'),
    '/posts'      => array('Posts:create', 'post'),
    // etc...
));

But obviously you can't have an array with duplicate keys so the second assignment to /posts will overwrite the first and there won't be a route pointing to Posts:index.

Right now a possible work around would be to use addControllerRoute which would go something like

$app->addControllerRoute('/posts', 'Posts:index')
    ->via('GET');

$app->addControllerRoute('/posts/:id', 'Posts:show')
    ->via('GET');

$app->addControllerRoute('/posts', 'Posts:create')
    ->via('POST');

// etc...

But that doesn't seem as elegant as it could be.

I was wondering if we could think of a better way to define multiple routes that point to the same url with different HTTP methods.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant