Klipfolio. The KPI Dashboard - Evolved
The KPI Dashboard – Evolved
1-877-233-6149
Contact Us

Making a REST request from a Klip

Problem:

I want to display data from a RESTful web service.

Solution:

To retrieve data from a RESTful web service, make an HTTP request using the URL that follows the syntax specified by the desired RESTful API.

In this article, we will use the Timeline method from Twitter's public REST API to get a user's statuses from twitter.com in XML format.

Example Klip

Download the sample Klip.

Note: Typically, you will want to make a REST request according to your user's input. For this reason, the sample Klip includes a search field whose input string is used as part of the URL; however, this is not part of the requirement for making a REST request.

A closer look at the sample Klip

Here's a snippet of code in the sample Klip that makes the HTTP request and gets the XML data from twitter.com:


var request = Engines.HTTP.newRequest( "http://api.twitter.com/1/statuses/user_timeline.xml?screen_name="+ searchName );

// Send an HTTP request
if ( request.send() ) {       

    if ( request.response.data ) {

        // Output the returned data in the Debug Window as a reference.
        // traceln( request.response.data );

        // Process the returned data
        Engines.Data.process( request.response.data );
    }
} 
else     {
    traceln( "Could not reach: " + request.url );
}
The searchName is the string the user entered in the search field. If, for example, wikipedia were entered, the request would be sent to:

http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=wikipedia

The script gets the data and processes it. Then, it is up to you to specify what to display in the Klip by writing the <style> block by matching XML tags. For this, follow from step 4 of the how-to article, Klip Development Fundamentals.

Leave a Comment

To leave a comment, you must sign in or register (it's free).

   
Comment Type:
Title:
Comment: