node.js and ql.io
Build Your Own HTTP APIs for Agility and Scale
OSCON July 20, 2012
1
Slide 2
Slide 2 text
Subbu Allamaraju
@sallamar
github.com/s3u
2
Slide 3
Slide 3 text
Jon LeBlanc
@jcleblanc
github.com/jcleblanc
3
Slide 4
Slide 4 text
How to consume
HTTP APIs cheaply
and efficiently
4
Slide 5
Slide 5 text
5
curl
-‐X
Slide 6
Slide 6 text
Real code (randomized)
Slide 7
Slide 7 text
7
Slide 8
Slide 8 text
8
Slide 9
Slide 9 text
9
Slide 10
Slide 10 text
10
Slide 11
Slide 11 text
11
Slide 12
Slide 12 text
12
Slide 13
Slide 13 text
13
Slide 14
Slide 14 text
14
Slide 15
Slide 15 text
Find things from A
For each thing, find details from B
For each thing, find more details from C
Merge results
Use case:
15
Slide 16
Slide 16 text
Find products
Find dominant categories of products
Look up category info
Merge categories with products
Use case:
16
Slide 17
Slide 17 text
Get stuff from A
If A is down, try from B
Annotate stuff with other stuff from C
Ignore some things from the stuff
Join all
Use case:
17
Slide 18
Slide 18 text
Producers
Client
[Really important client]
Why don't you give me an
API optimized for my use
cases?
Server
[Really important producer]
Thanks. Get a number
and stand in the line!
18
Slide 19
Slide 19 text
Producers
Client
Server
[Really important producer]
Thanks. Get a number
and stand in the line!
Who gets to
decide the right
thing?
19
[Really important client]
Why don't you give me an
API optimized for my use
cases?
A domain specific language for
HTTP client programming
22
Slide 23
Slide 23 text
cut down lines of code
reduce no of requests
save bandwidth
23
Slide 24
Slide 24 text
24
Slide 25
Slide 25 text
http://ql.io/console
25
Slide 26
Slide 26 text
26
Server
Web Node.js
ql.io Installation Modes
Slide 27
Slide 27 text
27
curl
http:///q?s=query
Slide 28
Slide 28 text
As a Standalone Server
Node Host
ql.io
Data
(internal
)
Data
(externa
l)
Slide 29
Slide 29 text
#
As
a
node.js
module
npm
install
ql.io-‐engine
Slide 30
Slide 30 text
//
Use
ql.io
from
node.js
var
Engine
=
require('ql.io-‐engine');
var
engine
=
new
Engine({
//OPTIONS
});
var
script
=
'…';
engine.execute(script,
function(emitter){
emitter.on("end",
function(err,
res){
…
});
});
Slide 31
Slide 31 text
Language:
Defining
a
Data
Source
Include
in
.ql
file
Include
in
Request