Web Services? |
[eluser]Teks[/eluser]
According to REST principles, the function in your controller that will be called should depend on the HTTP REQUEST-METHOD. It is more-or-less accepted, that the basic CRUD operations should be mapped to the request methods GET, POST, PUT and DELETE, like this: * POST = Create * GET = Read * PUT = Update * DELETE = Delete The problem with this, is that CodeIgniter's routing mechanism by default does NOT take into consideration the HTTP REQUEST-METHOD. Those articles above show you a couple of techniques that will patch the built-in routing mechanism with your own class, so that the REQUEST-METHOD can dictate which function in your controller gets called. So, in practice, it would work like this - let's suppose I have a database of recipes, which are accessible on the 'net via a RESTful interface. Let's suppose my site is "www.teksrecipes.com", and that I have a controller called 'recipes' that handles everything. Let's suppose that I want to create a new recipe, for chocolate cake, in my database. I could send a PUT request, with the relevant data, to: http://www.teksrecipes.com/recipes/chocolate_cake.html Because the request is a PUT request, it should be directed to the appropriate "create()" function in my "recipes.php" controller. In order to later retrieve the chocolate cake recipe, I would send a GET request to the same address: http://www.teksrecipes.com/recipes/chocolate_cake.html If I wanted to *update* the recipe, I would access *the same address*, but using a POST request instead, with the updated information: http://www.teksrecipes.com/recipes/chocolate_cake.html If I wanted to *delete* the chocolate cake recipe, I would access the same address again, but using a DELETE request: http://www.teksrecipes.com/recipes/chocolate_cake.html I hope this helps. |
Messages In This Thread |
Web Services? - by El Forum - 12-13-2008, 12:14 PM
Web Services? - by El Forum - 12-14-2008, 01:49 AM
Web Services? - by El Forum - 12-14-2008, 03:18 PM
Web Services? - by El Forum - 12-14-2008, 04:11 PM
Web Services? - by El Forum - 12-15-2008, 02:11 AM
Web Services? - by El Forum - 12-15-2008, 05:41 AM
Web Services? - by El Forum - 12-15-2008, 06:51 AM
Web Services? - by El Forum - 12-15-2008, 07:18 AM
|