I’ve written a small example to show how to call REST services from Flex.

See working example: click here

Source code: click here

Flex Yahoo! Image Search REST Sample

The sample is source code enabled.
Accessing REST services with Flex is pretty simple. The main work done in the code is done by the following code:

<mx:HTTPService id=”yahoo_image_search”
url=”http://search.yahooapis.com/ImageSearchService/V1/imageSearch”>
<mx:request>
<appid>get your id from yahoo</appid>
<query>{input.text}</query>
</mx:request>
</mx:HTTPService>

Here we are calling the REST API with HTTP Service and passing it two required parameters:
appid - The application ID. See Application IDs for more information.
query - The query to search for. Use + to include terms, - to exclude terms, and put quotes around “exact phrase”.

You can find the complete description of the Yahoo! Image Search API here - http://developer.yahoo.com/search/image/V1/imageSearch.html

The response returned by the API is in XML format:

<ResultSet xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns=”urn:yahoo:srchmi” xsi:schemaLocation=”urn:yahoo:srchmi http://search.yahooapis.com/ImageSearchService/V1/ImageSearchResponse.xsd” totalResultsAvailable=”190145″ totalResultsReturned=”2″ firstResultPosition=”1″>
<Result>
<Title>Madonna photo Madonna 6200315</Title>
<Summary />
<Url>
http://www.poster.net/madonna/madonna-photo-madonna-6200315.jpg</Url>

Hence, to access the main results we need to access the <Result> node inside of <ResultSet>, which is pretty state forward with our Datagrid.



Comments

  1. 1
    ash
    June 20th, 2007 at 9:54 pm

    Did you ever try searching on and showing/playing yahoo videos? I could get search to work, but I could never get playing of the videos to work.

  2. 2
    Frzk
    December 13th, 2007 at 9:25 pm

    I fail in treating error code for REST.
    Have you found anything on faulting request ?

  3. 3
    Andy
    December 19th, 2007 at 10:18 pm

    Oh, and did not know about it. Thanks for the information …

Leave a Comment

blank