Showing posts with label API. Show all posts
Showing posts with label API. Show all posts

Tuesday, April 15, 2008

Access RESTful API in 2 LOC

Today I was playing with json-lib and FriendFeed API in Groovy console and was able to fetch feed's JSON representation and do a simple result filtering in 2 lines of code! So, for example, here are all my recent twitter entries (filtered from all the other content e.g. different services like flickr, amazon, etc.):


import net.sf.json.*

def friendFeedJsonResponse = new URL('http://friendfeed.com/api/feed/user/dima767').text
JSONObject.fromObject(friendFeedJsonResponse).entries.
findAll { it.service.id == 'twitter' }.
each { println it.title }
I know it is a very simple example, but IMO, with an 'expressiveness' and 'compactness' of Groovy, in the majority of cases, there is no need for a 'wrapper' library and various web APIs could be used 'as is'

Later...