-
Notifications
You must be signed in to change notification settings - Fork 1
Getting Started with YQL
To use YQL, you make a REST call to one of the YQL Web Service URLs. The YQL statement is passed as a query parameter to a YQL Web Service URL. Let's look at an example YQL statement, the YQL Web Service URLs, and the response format shown in the YQL Console.
The following YQL statement makes a query on the local.search
table and filters
the results based on the zip code and search query:
select * from local.search where zip='94085' and query='pizza'
The YQL Web Service has four URLs, one for publicly available data, one for data that requires authorization, and two for streaming data.
The following URL allows access to public data, which does not require authorization:
http://query.yahooapis.com/v1/public/yql?[query_params]
The next URL requires authorization by OAuth and allows access to both public and private data:
http://query.yahooapis.com/v1/yql?[query_params]
The YQL Web Service also has URLs for streaming both public and private data:
So, the next logical step is to learn how to append the YQL statement to the YQL Web Service URLs.
The query parameter that is used is simply q
:
?q=select * from local.search where zip='94085' and query='pizza'
Thus, if we were going to call the YQL Web Service with our first example YQL statement, we would use the following URL:
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20local.search%20where%20zip%3D'94085'%20and%20query%3D'pizza'
<http://query.yahooapis.com/v1/public/yql?q=select * from local.search where zip='94085' and query='pizza'>
YQL responses can be returned in XML or JSON. You specify the format with the query parameter format
.
The default format is XML. If we wanted JSON returned for our pizza query, we would append
format=json
to the query string:
The best way to see the response is to run the query in the YQL console. You'll see that the <results>
element, or
the results
array in JSON, containing many <Result>
elements containing our rows of data. If the Debug checkbox is checked,
you'll also see the <diagnostics>
element, which has information to help you debug your query or table. To see the response in JSON,
just check the JSON radio button.