O'Reilly logo

Programming Social Applications by Jonathan LeBlanc

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Making Standard Data Requests

Unless you’re building a site that requires a secure data transfer, you’ll access the majority of your data through standard RESTful server requests. You can make these standard requests through osapi.http.method, where method is get, put, post, or delete.

Since we are using the osapi JavaScript functionality, we will need to add a Require statement to make the request methods available for us to use. Once the methods are available, we can use them to build out a functional example to capture data from an external source and display the content within the application.

The following example will make a GET request to Flickr via the Yahoo! Query Language (YQL) to return photos that match the search term “Montreal.” Those results are then parsed, and <img> tags are generated based on the results of each photo and displayed within the application:

<?xml version="1.0" encoding="utf-8"?> <Module> <ModulePrefs title="GET Request to Flickr via YQL"> <Require feature="osapi"/> </ModulePrefs> <Content type="html" view="canvas"> <![CDATA[ <div id="imgContainer"></div> <script type="text/javascript"> //GET request callback function requestCallback(response){ var photolist = response.content.query.results.photo, html = ""; //loop through each image and create an <img> tag for (var i in photolist){ if (photolist.hasOwnProperty(i)){ html += "<img src='http://farm" + photolist[i].farm + ".static.flickr.com/" + photolist[i].server + "/" + photolist[i].id + "_" + photolist[i].secret ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required