Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

New File

  • Loading branch information...
commit 98a7458626be5c0fa560b637aaa6a9af28aa3c22 1 parent 7549b07
Derek Gathright derek authored

Showing 1 changed file with 59 additions and 0 deletions. Show diff stats Hide diff stats

  1. +59 0 README.md
59 README.md
Source Rendered
... ... @@ -0,0 +1,59 @@
  1 +About
  2 +---------------
  3 +
  4 +YQL is awesome, but sometimes you don't need to use all the SQL-like features of it and you just want make an API service with JavaScript. **Executor to the rescue**. Think of it like the NoSQL version of YQL.
  5 +
  6 +Executor is a web application that simply generates an [open datatable](http://www.datatables.org/) for you in effort to simplify and expedite the development process. While Executor does nothing magic, I believe it lowers the learning curve and removes the intricacies of understanding YQL from the equation. As long as you know JavaScript, you can now use YQL to create dynamic API services via open datatables.
  7 +
  8 +The neat things with datatables is that once you have one complete, you now have an API service that you can pass dynamic data to via the querystring. Think the [REST URL](http://s89997654.onlinehome.us/screencaps/skitched-20110924-235709.jpg) YQL uses is too long and ugly? Use YQL's [Console](https://developer.yahoo.com/yql/console/) to create a query alias. So for example, here is an API service that searches YouTube, Justin.TV, Flickr, and Netflix for the specified term in the querystring, [http://query.yahooapis.com/v1/public/yql/derek/mediasearch?query=kittens](http://query.yahooapis.com/v1/public/yql/derek/mediasearch?query=kittens). The best part is, you don't thave to worry about hosting it. Let Yahoo worry about that.
  9 +
  10 +`<execute>`
  11 +--------
  12 +Within YQL, there's a little-known feature, the `<execute>` sub-element. Inside of `<execute>`, you can put whatever JavaScript you want to execute inside of YQL's [Rhino] engine. Yes, you heard me right, any JavaScript you want to pass in. It's pretty rad.
  13 +
  14 +Inside of `<execute>`, you start with 2 global objects
  15 +
  16 + - [y] - A library of utility methods
  17 + - [response] - contains the results of the YQL response
  18 +
  19 +Note, there's also a 3rd global ([request]), but that won't be very useful for Executor. So ignore it for now.
  20 +
  21 +Let's start with the important one first, `response`. There's really not much to it aside from `response.object` which is the property you assign your output to. This will be the data received by the client making the YQL request. This is just about the most basic example of an `<execute>` sub-element:
  22 +
  23 +> `response.object =
  24 +<items>
  25 + <item>foo</item>
  26 + <item>bar</item>
  27 +</items>;`
  28 +
  29 +Now, if you really want to take advantage of `<execute>` and earn some gold stars, you'll want to investigate the `y` object a little more closely. This object contains really useful things like:
  30 +
  31 + - `y.log(string)` - Log messages to `<diagnostics>`
  32 + - `y.rest(url)` - Execute HTTP requests
  33 + - `y.query(query)` - Execute YQL queries
  34 + - `y.crypto.encodeMd5(string)` - Generate an MD5
  35 + - `y.include(url)` - Includes and evals a JavaScript file
  36 + - `y.parseJson(json_string)` - Returns a JavaScript object when given a well-formed JSON string. I sometimes have issues with this method, and instead just use `eval()`. \**shrugs**
  37 + - `y.jsonToXml(object)` - Converts a JavaScript/JSON object into E4X/XML
  38 + - `y.xmlToJson(object)` - Converts an E4X/XML object into a JSON object
  39 +
  40 +There are quite a few more methods, but those are the most commonly used ones.
  41 +
  42 +E4X
  43 +------
  44 +
  45 +The awesome part about [E4X](http://en.wikipedia.org/wiki/ECMAScript_for_XML) is that you get XML natives in JavaScript. The awful part of E4X is that it means you are using XML inside of JavaScript. Read more into it if you are curious because a detailed explanation is well beyond the scope of this README.
  46 +
  47 +Who/What/When/Where?
  48 +-------
  49 +
  50 +This was hacked together in about 10 hours by [@derek](http://twitter.com/derek) at a Y! HackU event in Berkeley on Sept 23rd/24th 2011.
  51 +
  52 +
  53 +
  54 + [y]:
  55 +http://developer.yahoo.com/yql/guide/yql-javascript-objects.html#yql-execute-yglobalobject
  56 + [request]: http://developer.yahoo.com/yql/guide/yql-javascript-objects.html#yql-execute-yrestobject
  57 + [response]: http://developer.yahoo.com/yql/guide/yql-javascript-objects.html#yql-execute-responseglobalobject
  58 + [rhino]: http://en.wikipedia.org/wiki/Rhino_%28JavaScript_engine%29
  59 +

0 comments on commit 98a7458

Please sign in to comment.
Something went wrong with that request. Please try again.