Start a free Courses trial
to watch this video
In this video we introduce what YQL is and how to use the YQL Console.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up[?mellow guitar music?] 0:00 [Think Vitamin Membership - Est. 2010] [membership.thinkvitamin.com] 0:03 [YQL - Introduction - with Jim Hoskins] 0:07 The Yahoo! Query Language, or YQL, is a web service from Yahoo 0:13 that allows you to query virtually any web service from a single url 0:16 using a uniform query language. 0:20 In this video, we'll learn what YQL is and see how to use the YQL console. 0:23 Web services are becoming a more and more important part of web development. 0:27 Many of our applications rely on real-world data from web services 0:31 or they need to interact with other applications around the web. 0:35 But web services can be tough. 0:39 They're all different and they often end up requiring 0:41 a bunch of different steps to get started. 0:43 You have to find the API you're looking for. 0:45 Often, you have to get an API key or a developer's key, 0:48 which sometimes requires you to provide personal info 0:51 or information about your application up front. 0:53 Then, you need to read the documentation in order to find the method that you want to call. 0:56 Finally, you end up calling the method, but then you go back to reading the documentation 1:01 to get information about how it's formatted or what might have gone wrong, 1:05 and then, you can finally use the data. 1:10 Now, the problems are that these APIs are all going to be formatted differently. 1:12 They might either be in the REST format, or using SOAP 1:16 or some other format that makes working with multiple APIs difficult 1:20 because you have to manage the different inputs and outputs that are provided by them. 1:24 Now, ideally, we just want to narrow it down to a few things. 1:29 We want to just be able to find a method, call the method, and use the data. 1:32 All this other stuff just seems like way too much work. 1:36 Well, fortunately, that's where YQL is very, very strong. 1:39 YQL stands for the Yahoo! Query Language, 1:43 and it's a service provided by Yahoo! that allows us to use various web services 1:46 in a neat and uniform manner. 1:51 Now, one of the biggest understandings is that YQL is more than just Yahoo! Web Services. 1:53 A lot of people think that YQL is simply a tool that allows you to use Yahoo!'s web services 1:59 like flickr or Maps or Weather or something like that, 2:04 but in fact, YQL is so much more than that. 2:07 It's really an API for the web. 2:10 YQL can be used to standardize almost any web service available, 2:12 and the way YQL standardizes the interface for working with APIs 2:16 is through the Yahoo! Query Language, which looks a lot like SQL. 2:20 Basically, all we want is to select something from somewhere 2:25 where certain conditions apply, so when we want to actually interact with a web service, 2:28 now we just need to figure out three things. 2:33 We want to figure out what is the thing we want to select. 2:35 Well, in the YQL query language, we can narrow down the results that come back. 2:37 It's normally easy to get the raw results with all of the data 2:41 so nine times out of ten, we're selecting * or selecting everything from our query. 2:45 Next, we need to figure out the somewhere--where are we getting it from? 2:51 Well, the different web services are stored in table names. 2:54 Now, there's different tables available from Yahoo, 2:58 and different tables that have been contributed to the community 3:01 and you can write your own tables if one doesn't already exist for your web service. 3:03 Finally, we need to figure out the conditions, 3:07 and these are basically just the parameters that you would normally pass 3:09 to your web service. 3:12 So the basic URL that we would always use for our query looks something like this. 3:14 It's always going to use the same endpoint with 3:18 the query.yahooapis.com/v1/public/yql 3:20 and then we pass it the ?q= being the {query} that we want to pass. 3:25 It will pass back either json or xml formatted data, based on what you request. 3:30 You can get some diagnostic information back while you're developing, 3:35 which is really helpful, and you can also use a callback name, 3:38 which will allow you to make a request to YQL from the browser 3:42 without having to worry about cross-domain issues. 3:45 Now, what's nice is that these last three are really optional, 3:47 so there's only one real endpoint that we have to worry about, 3:50 and we just need to worry about constructing the query. 3:54 So let's actually check YQL out. 3:57 When you use YQL, you're going to be using the YQL console a lot. 3:59 This is a tool that allows you to explore and test out your queries 4:03 and easily get the URLs that you would want to use for that particular query. 4:07 So it's at developer.yahoo.com/yql/console 4:12 and these are the main parts. 4:17 At the top, we'll see the YQL statement that you want to be executing, 4:20 and there are some options here-- 4:24 like if we want our result in XML or JSON-- 4:26 and down here is where we can see the results of our queries. 4:28 Now, along the sidebar here, we have a list of tables that are available to us 4:32 that we can explore for our documentation. 4:37 Now, this is an example query that searches the flickr photo search API 4:39 or flickr photo search table in order to search for the word "Cat." 4:43 So it looks like a normal SQL query except now we're doing it against a web service. 4:48 So what we use is the select * which means we're going to select everything 4:54 from our results and we're going to use the flickr.photos.search table. 4:57 We could find out more about this table in a second, 5:02 and then we'll see that we have a where condition where the text="Cat." 5:05 So basically, we're searching for Cat, and when we run this query, 5:09 we get some information back. 5:13 Here's some diagnostic information, but the results look a little bit like this: 5:16 we have photo objects with all of the information that we would need, 5:19 and so on and so forth, 5:22 and it gives us a few different views of this data. 5:24 And we can go to the tree view 5:26 and see it expand and contract like this. 5:28 Also, if we wanted to get our data back in JSON as opposed to XML, 5:31 we can do that very quickly. 5:35 Let me go to the formatted view so we can see that. 5:38 So it's the same information coming back-- 5:40 they just transfer the XML to JSON for us if we want it. 5:43 Now also, when we're using JSON, we can pass a callback function, 5:47 which will be wrapped around the result so you can use the JSONP 5:50 or rather, put it in a script tag with a callback function 5:55 and this technique allows you to call the YQL web services directly from the browser 5:58 without having to worry about cross-domain requests. 6:03 Now, if we look over here, we see some data tables, 6:06 and right now, these are just the tables that are available based on Yahoo! services, 6:09 so like Yahoo! Answers, flickr, some mapped information, Weather, and so on, 6:14 so we could take a look at weather.forecasts, 6:19 and when we click on it, it will give us an example query that we can play with, 6:22 or if we click on the description right next to it, 6:25 we can use describe whether forecast and I'm going to flip it to XML 6:28 because it's a little easier to read, 6:32 and we can actually get some information about the table itself. 6:34 So we can see the author, some description and documentation information 6:37 as well as a sample query 6:41 and here we can see a select request will have a location that is required in the where string 6:44 so you can take a look at some of these tables and play with them. 6:50 What's even cooler is there are community tables, which are contributed 6:54 by the community at large, and that means there's over a thousand tables 6:57 already built up for us to use-- 7:01 from everything like Amazon, we have Twitter, a lot of different web services, 7:03 and a lot of cool stuff that you can use-- 7:09 so definitely take a look around this. 7:11 Now, the most powerful set of tables is actually at the bottom here, 7:13 and we'll be looking at it in future videos--the data tables, 7:16 and these tables allow us to actually scrape raw information, 7:19 whether it's from an Atom feed, a CSV file, an HTML file, and a lot of other different formats. 7:22 So using YQL, you can even create a web service for a website 7:30 that doesn't have an official API simply by pointing it at an HTML page 7:34 and collecting the information you need off of that. 7:39 Now that we know about YQL, the next step is accessing it from our web applications. 7:42 In the upcoming videos, we'll see the different ways we can consume YQL data 7:45 from our web apps. 7:49 [?mellow guitar music?] 7:51 [Think Vitamin Membership - Est. 2010] [membership.thinkvitamin.com] 7:53
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up