CodeIgniter Forums
Web Services? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Web Services? (/thread-13968.html)



Web Services? - El Forum - 12-13-2008

[eluser]Iverson[/eluser]
Anybody familiar with how these work? I've read tutorials but I'm still not quite grasping it. I'm trying to figure out how sites like Kayak pull their data. Obviously I'm trying to figure out if this could this be done using PHP b.k.a. CI. Any direction would be greatly appreciated!


Web Services? - El Forum - 12-14-2008

[eluser]phpserver[/eluser]
http://wso2.org/projects/wsf/php Wso2 is a web services framework just like codeigniter going as per what a web applications framework is but let not the definition confuse you.View what wso2 offers you in terms of building web services here http://wso2.org/projects/wsf/php and i am sure you will find some kind of help.

If my info was helpful let me know.


Web Services? - El Forum - 12-14-2008

[eluser]Teks[/eluser]
You may find the following blog post helpful:

RESTful Controller in CodeIgniter


Web Services? - El Forum - 12-14-2008

[eluser]jaswinder_rana[/eluser]
Thanks Tecks. Wonderful read that.

In that tutorial, there is a mention of another way to do this, at http://blog.medryx.org/2008/10/03/codeigniter-rest/.

My question is regarding the 7th comment in that second article. It seems it wasn't answered there and I am hoping I'll get it here.

Also, are there plans to include either those APIs or one designed by CodeIgniter for REST? Admittedly I haven't played much with REST architecture but it's now on my ToDo list.

Thanks


Web Services? - El Forum - 12-15-2008

[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.


Web Services? - El Forum - 12-15-2008

[eluser]phpserver[/eluser]
Thanks Teks,its very helpful


Web Services? - El Forum - 12-15-2008

[eluser]jaswinder_rana[/eluser]
Thanks Teks. You make it very simple when you put it like that Smile

So, does it mean that anyone can delete (could be insert) that recipe? Or does the page expect some authentication info??

As I said, I am just starting with REST. So, I am trying to see how it works. From what I read, this will open our DB to everyone. They can insert and delete at will. Is this correct?

What are the common circumstances where I might use it? Any time I wish? Or are there certain requirements for applying RESTful?

I might use it in my application and am trying to see how to implement it in CI.

Thanks


Web Services? - El Forum - 12-15-2008

[eluser]Iverson[/eluser]
THIS post is why CI has the best PHP forum on the internet. Hands down! :coolsmile: I'm about to start looking at the REST controller... Thanks guys! Maybe I'm jumping the gun here by asking this before I read, but how does this relate to car rental websites, airfare sites, etc.? Are these people paying to access the airlines' web services or is there somewhere where you can get an api or interface?