RESTful web services api coding with PHP and CuRL

Hi,
I have had a chance to work on the RESTful web services offered by some of the giants in the internet industry, major ones being Rackspace, Yahoo and Google (especially with the custom search). It requires serious programming skills and is not at all for the faint-hearted. My experience involved downloading and uploading files with Rackspace cloud files api to Yahoo store partner management and even the custom search by Google.
RESTful api as the name suggests is basically transfer of state of server from and its representation. When you want to perform operations on a remote server, REST can provide maximum reliability and security. The trick is to represent the request and response in a way that the communication is easy and swift, but at the same time being reliable.
The requirement from the user endpoint to successfully carryout the operations on remote server is a formatted request sent to a specific location on the server. This location fires up a command on the remote server which performs the required operation. The user here is called client and the server is, well a server.
When the client performs a request, the REST protocol requires the request to have all the data available in a single request itself. So no temporary data is stored on the server, except for the temporary authentication token(which is usually present). So this makes the server highly reliable along with being easy to reach. So this suggests that even if we are performing same operation again and again on same place on server, we have to clearly specify the location and operation in every request.
For example I am performing an operation an operation on a directory of the server through my computer, this operation will change the state of the server. So I create a request, send to appropriate directory on the server, the server is now initiated and operation is performed, at this time the client is considered to be in transition, then the server completes the operation and sends the response back. This might look new to some, but its basically the exact process that happens every time you start browsing any website. For example if you type http://www.google.com/ in your browser and hit enter, a request is created  by your browser and sent to the root directory at google.com which then performs the operation of generating a webpage and sends the response back. This response usually contains head (headers) and body (content). The headers are usually for the browsers own use while the body is displayed to the user.
Another good example would be when you accept a friend request on your social networking site. What happens underneath the browser, when you click that button, is that your browser creates a request and sends it to a specific directory on the server. The server carries out the operation of updating the database and sending a notification to the other user, that the friend request is accepted, and returns a response to the browser. The browser displays the received response to the user. If the same process had to happen again, the REST constrains that each piece on information exchanged in the first time should be exchanged again.
This gives rise to endless possibilities like exchanging text or even binary data. To carry out this same process in PHP to accomplish some major tasks over remote servers, we need a way to send requests and  receive response. CuRL library for PHP does the trick here. We can generate the request in the form of string or even binary data (if required to be uploaded to the server) and send it over HTTP. HTTP offers several methods like GET, POST, PUT and DELETE. These methods are highly useful for distinguishing the kind of operation to be performed on the server.
The Yahoo store api takes XML formatted data, while Rackspace cloud understands JSON and XML. There are major differences between the services offered by each of the providers and so the requests are also different. This makes the possibility of creating a reusable code very difficult.

To be continued... visit back soon.

--
Amit Kriplani
PHP Web/Application Developer
Blog:http://blog.amitkriplani.com
Mobile: +91-9913932644
MSN: amitk87@hotmail.com
Gmail: amitkriplani5@gmail.com
Yahoo: amitkriplani@ymail.com
Skype: amitkriplani
Twitter: @amitk87