13
JSONH An story in mobile API optimisation & how to get data stuff faster. Tuesday, 1 April 14

JSONH & Mobile APIs

Embed Size (px)

DESCRIPTION

London Titanium talk on compressing JSON responses

Citation preview

Page 1: JSONH & Mobile APIs

JSONHAn story in mobile API optimisation & how to get data

stuff faster.

Tuesday, 1 April 14

Page 2: JSONH & Mobile APIs

Tuesday, 1 April 14

Back in the day when I could barely pronounce API and for me, JavaScript was some esoteric magic that induced pain and wonder.

Page 3: JSONH & Mobile APIs

Tuesday, 1 April 14

Mobile phones were unwieldy bricks of plastic and metal with huge antennas and then hefty charge

W.A.P was the new kid on the block and I had to print out yet another manual to accompany my hefty collection of mySQL 3.x and HTML / HTTP specs

I can remember that it filled me with hope & excitement period and helped cross the bridge between our flashy web bracket plan intended bracket and these always connected devices with screens the size of stamps

Page 4: JSONH & Mobile APIs

Tuesday, 1 April 14

Actually taking to where what's the point of this well today, you see, we have a super bit, quadruple powered Infinity Gauntlet charged broadband speeds...

It's made us a little lazy KiloBytes?... pah! Peanuts four our broadband connected society…

Page 5: JSONH & Mobile APIs

Tuesday, 1 April 14

But then came the iPhone followed by nestle droid sorry android and the rabbit holes appeared we developers dived in red pill please and our complacency led us to grow home bellies

Not really but my point is this to be really care or understand how user base not only in the first I know we do so how can we improve our code designs technical debt and get out of a lazy programming interface frame of mind

Page 6: JSONH & Mobile APIs

Cost of an API call

Tuesday, 1 April 14

I was looking for only that I wanted to increase performance speed reducing packet size & cost of an API call. Specifically for a mobile project talking to a node.ACS service interacting with one or more APIs

Page 7: JSONH & Mobile APIs

Mobile API query

TELCO WIFI

MIDDLEWARE SERVER

DATA BACKBONE

API PROVIDER DATA SOURCE

Cost of an HTTP

REQUEST...

Tuesday, 1 April 14

EXPLAIN DIAGRAM & MULTIPLE REQUESTS

Page 9: JSONH & Mobile APIs

Compression Comparison

JSONH looked best.

Tuesday, 1 April 14

Page 10: JSONH & Mobile APIs

Setting Up - 1

GET JSONH library

GET JSONminify (optional to strip whitespace/comments)

Add both libraries into your project.

Add to Node.ACS & into your Ti project

Tuesday, 1 April 14

Page 11: JSONH & Mobile APIs

Setting Up - 2Include the libs into your Node.ACS/Ti App / Server

Minify & pack the data

Return string

var jsonminify = require("jsonminify");var JSONH = require('jsonh');

! ! var resString = _minifyJS(data);! ! resString.Contents = JSONH.pack(resString.Contents);

! ! return (JSON.stringify(resString));

Tuesday, 1 April 14

Page 12: JSONH & Mobile APIs

Setting Up - 3decompress collection in app

! function callback(e) {! ! Ti.API.log('mobile request callback');! ! var rJson = JSON.parse(e);! ! // get return data and parse then unpack the JSON.! ! rJson.Contents = JSONH.unpack(rJson.Contents);! ! return rJson;! }

Tuesday, 1 April 14

Page 13: JSONH & Mobile APIs

ACS/AWS

3rd Party Service API Method

Stringify Reponse

Minify Reponse

pack JSONH homogenous

collection node

Mobile Function requires Data/ API

Call

Q

Q

Q

Parse responseText if required

UNPACK JSONH homogenous

collection node

API: XHR callback

API: XHR HTTPRequest

Node.ACS

Service API Method

JSON

D

Q Decision based on query parameters

D Data response from HTTPClient

API: callback

API: HTTPRequest

JSON / (string/min)ified

D

Mobile

JSON Compression: HPACK using jsonh.js Mobile > Node.ACS > ACS > Mobile

Ketan Majmudar

Tuesday, 1 April 14