Sunday, 13 February 2011


REST

The design of twitter API uses the principle of Restful system. This is called representational state transfer. REST is an architectural design or style which can be employed to create a web service that focus on system resources. This also   involves how resource states are issued and sent over a HTTP by different client written in different languages.
Basic design principle involve in REST are usage of HTTP more explicitly , Stateless , expose directory  structure ( like URL) , transfer XML , Java Script object notation or both.

Explicit usage of HTTP method

One of the futures of a RESTful web service is a detailed application of HTTP method in a way that follows protocol as laid out by RFC 2616. twitter API permit 4 kind of  HTTP request.: GET , POST , DELETE and UPDATE.

GET
 The Get method accepts URL and uses it to retrieve something from another server after necessary processing is done. If the web server is PHP web page , the Get method will capture the HTML generated by the   PHP and not the PHP code itself. GET method is use to carry out query, in which the web server will process the query and produce the result with the issued query. GET is a method that must be free from side effect call idempotent, must not have side effect for performing Get operation , and must be cacheable.  
Example of twitter API that are accessed with GET methods:


https://twitter.com/direct_messages.xml
https://twitter.com/favorites.xml
https://twitter.com/followers/ids.xml
https://twitter.com/friends/ids.xml
https://twitter.com/friendships/exists.xml
https://twitter.com/help/test.xml
https://twitter.com/statuses/followers.xml
https://twitter.com/statuses/friends.xml
https://twitter.com/statuses/friends_timeline.xml
https://twitter.com/statuses/public_timeline.xml
https://twitter.com/statuses/replies.xml
https://twitter.com/statuses/show/id.xml
https://twitter.com/statuses/user_timeline.xml
https://twitter.com/users/show/id.xml

The following can be written in json by changing the XML extension to json.


POST
The POST method is required for API method that actually makes changes to twitter severs, rather than just retrieving data.  POST is use to establish a resources on a server. In twitter API the following method required POST request handling:

https://twitter.com/account/update_delivery_device.xml
https://twitter.com/account/update_location.xml
https://twitter.com/account/update_profile.xml
https://twitter.com/account/update_profile_colors.xml
https://twitter.com/account/update_profile_background_image.xml
https://twitter.com/account/update_profile_image.xml
https://twitter.com/blocks/create/id.xml
https://twitter.com/blocks/destroy/id.xml
https://twitter.com/direct_messages/destroy/id.xml
https://twitter.com/direct_messages/new.xml
https://twitter.com/favorites/create/id.xml

DELETE

The purpose of this type of HTTP call is to instruct the remote server to remove the requested URL resources. The DELETE method must be idempotent which means the request can be done in multiple times.

   https://twitter.com/blocks/destroy/id.xml
https://twitter.com/favorites/destroy/id.xml
https://twitter.com/friendships/destroy/id.xml
https://twitter.com/direct_messages/destroy/id.xml
https://twitter.com/statuses/destroy/id.xml

  





No comments:

Post a Comment