{"issue":{"created_at":"2011-11-05T23:56:24Z","state":"closed","updated_at":"2011-12-02T12:42:32Z","comments":6,"user":{"gravatar_id":"4435c5599a20082667fa144ef303afcf","id":1059452,"url":"https://api.github.com/users/knudpotente","avatar_url":"https://secure.gravatar.com/avatar/4435c5599a20082667fa144ef303afcf?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"knudpotente"},"body":"In a RESTful API, the URI should identify *only* the resource that is being acted on - for instance:\r\n\r\n1. http://myserver.com/monkeys/ - identifies the list of monkeys on the server\r\n2. http://myserver.com/monkeys/33 - identifies monkey id 33 on the server\r\n3. http://myserver.com/monkeys/33/bananas - identifies the list of bananas that belong to monkey 33\r\n\r\nIn order to identify the *action* that is to be performed with these resources, in a RESTful API we use *only* the HTTP verb:\r\n\r\n1. GET http://myserver.com/monkeys/ - I want to retrieve the list of monkeys from the server\r\n2. GET http://myserver.com/monkeys/33 - I want to retrieve the monkey who has id 33\r\n3. GET http://myserver.com/monkeys?country=Kenya&sex=M - I want to retrieve a list of male monkeys from Kenya\r\n4. POST http://myserver.com/monkeys/ - I am creating a new monkey record\r\n5. POST http://myserver.com/monkeys/33/bananas - I am creating a new banana record for monkey 33\r\n6. PUT http://myserver.com/monkeys/33 - I am updating the record of monkey 33 \r\n    (can also be used to create a new record, if monkey 33 doesn't already exist)\r\n7. DELETE http://myserver.com/monkey/33 - I want to delete monkey 33 from the server.\r\n\r\nAs can be seen, in a RESTful API the action is NOT specified in the URI - this is a very important distinction between RESTful and non-RESTful APIs. The following, for instance, is **not** a RESTful URI:\r\n\r\n* http://myserver.com/monkeys/add \r\n\r\nBecause this URI specifies an *action*, not a resource.\r\n\r\nIn a RESTful interface, we should only ever have to deal with 4 actions, and a RESTful controller, therefore, should only need to have **4 functions**: get(), post(), put() and delete().\r\n\r\nIn 1.1-RC1, however, the 'standard' Controller_Rest seems to rely on the programmer having to use action-based URIs in order to route to an appropriate function. Even though it's a 'REST Controller', it is not using the HTTP method to determine what action to take on the resource. This seems to be teaching and promoting un-RESTful implementations. \r\n\r\nIt is reasonably trivial to implement 'standard' RESTful routing, simply by adding the following router() function at the beginning of a Controller_Rest sub-class:\r\n\r\n```php\r\n\r\n\tpublic function router($res, array $args){\r\n\t\tparent::router($res, $args);\r\n\t\t\r\n\t\tswitch (Input::method()){\r\n\t\t\tcase \"GET\":\r\n\t\t\t\t$this->get_index($res,$args);\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"POST\":\r\n\t\t\t\t$this->post_index($res,$args);\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"PUT\":\r\n\t\t\t\t$this->put_index($res,$args);\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"DELETE\":\r\n\t\t\t\t$this->delete_index($res,$args);\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\t// The request uses an unsupported http method\r\n                // Handle the error here - i.e.:\r\n                $data['error'] = \"Unsupported HTTP method request.\";\r\n\t\t\t\t$this->response($data);\r\n\t\t}\r\n\t}\r\n```\r\n\r\nThe controller then has to implement the appropriate *get_index(), post_index(), put_index() and delete_index()* functions.\r\n\r\nIt seems to me, that this should be the **default** behaviour and setup of a Controller_Rest class. If the programmer needs to implement action-based URIs, then they are diverging from the RESTful standard, and **they** should have to use router() - and not the other way around.","assignee":null,"labels":[],"id":2154229,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"number":649,"title":"Controller_Rest Promotes Non-RESTful URIs","closed_at":"2011-11-28T21:09:47Z","html_url":"https://github.com/fuel/core/issues/649","url":"https://api.github.com/repos/fuel/core/issues/649","milestone":null},"action":"created","comment":{"created_at":"2011-12-02T12:42:32Z","updated_at":"2011-12-02T12:42:32Z","user":{"gravatar_id":"4435c5599a20082667fa144ef303afcf","id":1059452,"url":"https://api.github.com/users/knudpotente","avatar_url":"https://secure.gravatar.com/avatar/4435c5599a20082667fa144ef303afcf?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"knudpotente"},"body":"Indeed, that is how i would expect it work. In my end, however, it doesn't: 'post_index' does not get called by default, nor put/get/delete_index. That is why I've had to use the routes() function, and that is the reason for this issue.\r\n\r\nI'm happy to hear that this is the desired and intended behaviour. The manual seems to imply that an explicit action is required in the URL.","id":2989548,"url":"https://api.github.com/repos/fuel/core/issues/comments/2989548"}}