September 29th, 2008The Design of the Twitter REST API
The REST API for Twitter is very simple to learn and implement. And it has a comprehensive documentation.
Here is some selected operations to just to show its design. Note that here userid should be replaced with a valid twitter user id or user name and the format should be changed to the required output format (.xml, json, rss, atom are possible output formats)
| Operation | HTTP Verb | URL | Example HTTP Request (Setting username as ‘dimuthu’ and the output format as .xml) |
| Get public (all users) statuses | GET | http://twitter.com/statuses/public_timeline | GET http://twitter.com/statuses/public_timeline |
| Get a user statuses | GET | http://twitter.com/statuses/user_timeline/userid.format | GET http://twitter.com/statuses/user_timeline/dimuthu.xml |
| Get a particular status | GET | http://twitter.com/statuses/show/statusid.format | GET http://twitter.com/statuses/show/938135815.xml |
| Create a new status | POST | http://twitter.com/statuses/update.format | POST http://twitter.com/statuses/update.xml Authorization: Basic xxxx ……….. <status>my status message</status> |
| Delete a particular status | DELETE/ POST | http://twitter.com/statuses/destroy/statusid.xml | DELETE http://twitter.com/statuses/destroy/939390294.xml Authorization: Basic xxxx ……….. |
After having look at this API, the first question I had was whether this API is actually RESTful. In RESTful design we expect to map a resource to a URL and do CRUD (Create, Read, Update and Delete) operations using request with different Http Verbs (POST, GET, PUT, DELETE) with that same URL. Look at my blog on RESTful CRUD Data Services Demo for more clarification.
So if ever the API is designed following the above theory it would have been like this.
| Operation | HTTP Request |
| Get all statuses | GET http://twitter.com/statuses.xml |
| Get a particular user statuses | GET http://twitter.com/users/{user_id}/statuses.xml |
| Get a particular statuses of a user | GET http://twitter.com/users/{user_id}/statuses/{status_id}.xml |
| Crete a particular statuses of a user | POST http://twitter.com/users/{user_id}/statuses.xml |
| Update a particular statuses of a user | PUT http://twitter.com/users/{user_id}/statuses/{status_id}.xml |
| Delete a particular statuses of a user | DELETE http://twitter.com/users/{user_id}/statuses/{status_id}.xml |
So I think although Twitter API is really nice and easy, it is not really a RESTful API. If it was really RESTful, URLs might have been more organized so more easier to remember or predict. But still this API allows thousands of third party application to talk to the twitter, demonstrating the value of providing web services over just providing some web pages in a website.
![[Ask]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/ask.png)
![[Bloglines]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/bloglines.png)
![[del.icio.us]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/digg.png)
![[diigo]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/diigo.png)
![[dzone]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/dzone.png)
![[Facebook]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/facebook.png)
![[Google]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/google.png)
![[MySpace]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/myspace.png)
![[MyWeb]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/myweb.png)
![[Newsvine]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/newsvine.png)
![[PlugIM]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/plugim.png)
![[Reddit]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/reddit.png)
![[Slashdot]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/slashdot.png)
![[Spurl]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/spurl.png)
![[StumbleUpon]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Twitter]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/twitter.png)
![[Windows Live]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/email.png)