RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport...
Transcript of RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport...
![Page 1: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/1.jpg)
RPC OVER INTERNET
![Page 2: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/2.jpg)
Web API: RPC over Internet• RPC calls mapped onto HTTP (GET or POST) • Synchronous call• Asynchronous call
• with callbacks
• External data representation• JSON (Java Simple Object Notation)
• http://www.json.org/json-it.html
• XML
• Protocols• REST, SOAP, JSONP, JSON-RPC, XML-RPC,…
![Page 3: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/3.jpg)
JSON
![Page 4: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/4.jpg)
JSON• Two fundamental structures:
See JSON Lint
![Page 5: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/5.jpg)
XML in a nutshell • XML (eXtensible Markup Language) is a language derived
from SGML (Standard Generalized Markup Language),from which HTML also derives.
• The key notion in the markup language familty is amarkup, something that describes some aspect of themarkup, something that describes some aspect of thedata
• In HTML markups define the appearance of thedocument, whereas in XML they define the meaning ofthe data
![Page 6: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/6.jpg)
XML in a nutshell• An XML document is a tree
• Data appear inside elements
• An element not only contains the data itself but alsoinformation describing the meaning of the datainformation describing the meaning of the data
![Page 7: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/7.jpg)
Example
Il Signore degli Anelli, di John Ronald Reuel Tolkien,
Bompiani.
Title
Author di John Ronald Reuel Tolkien, Bompiani.
Editor
![Page 8: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/8.jpg)
Example<book>
<title> Il Signore degli Anelli
</title><author>
John R. R. Tolkien</author>
Title
Author
Editor
Book Elements
</author><editore>
Bompiani</editor>
</book>
Editor
Tips : Browser allows to see the structure of the document
![Page 9: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/9.jpg)
Elements and attribute<title>
Il Signore degli Anelli</title>
Data
Attribute (key/value pair)Tag
<title pages=“345”> Il Signore degli Anelli
</title>
Attribute (key/value pair)
![Page 10: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/10.jpg)
Well formed document
![Page 11: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/11.jpg)
Valid document• Document that follows composition rules about the its
structure• Two solutions• Document Type Definition
• Easier, less ‘powerfull’• Easier, less ‘powerfull’
• XML Schema• More complex, more powerfull
![Page 12: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/12.jpg)
WFD and validation
XMLDocument
Syntax check
Semantic check
Grammar
![Page 13: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/13.jpg)
XML-RPC
![Page 14: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/14.jpg)
Overview of XML-RPC• Data Model
• Scalar• Struct• Array
• Messages• Messages• Request message• Response message• Error message
![Page 15: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/15.jpg)
Scalar types
Tag Type Example
<i4> or <int> four-byte signed integer -12
<boolean> 0 (false) or 1 (true) 1
<string> string hello world
<double> double-precision signed floating point number
-12.214
<dateTime.iso8601> date/time 20101504T09:30:00
<base64> base64-encoded binary eW91IGNhbid0IHJlYWQgdGhpcyE=
![Page 16: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/16.jpg)
Struct type
<struct><member>
<name>lowerBound</name><value><i4>18</i4></value>
</member>
<member><name>upperBound</name><value><i4>139</i4></value>
</member></struct>
![Page 17: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/17.jpg)
Array type
<array><data>
<value><i4>12</i4></value><value><string>Egypt</string></value><value><boolean>0</boolean></value><value><i4>-31</i4></value>
</data></array>
![Page 18: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/18.jpg)
Request message
• Root element: methodCall• contains a MethodName element and a paramselement
• MethodName contains the name of the procedure • MethodName contains the name of the procedure being called
• Params is a list of values for the parameters
![Page 19: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/19.jpg)
Example<?xml version="1.0"?>
<methodCall>
<methodName>XXX</methodName>
<params>
<param>
<value><i4>123</i4></value>
</param>
<param> <param>
<value><double>12.3</double></value>
</param>
</params>
</methodCall>
![Page 20: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/20.jpg)
Example<?xml version="1.0"?>
<methodCall>
<methodName> XXX</methodName>
<params>
<param>
<value><i4>123</i4></value>
</param>
<param>
<value><double>12.3</double></value>
methodCall
XXX
methodName
params
param value i4123<value><double>12.3</double></value>
</param>
</params>
</methodCall>param value double
123
12.3
![Page 21: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/21.jpg)
Example<?xml version="1.0"?>
<methodCall>
<methodName>Scuola XXX</methodName>
<params>
<param>
<value><i4>123</i4></value>
</param>
<param>
<value><double>12.3</double></value>
methodCall
XXX
methodName
params
param value i4123<value><double>12.3</double></value>
</param>
</params>
</methodCall>param value double
123
12.3
methodNameparams
paramparam
doublei4
methodCall
![Page 22: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/22.jpg)
Complete request messagePOST /xmlrpc HTTP 1.0User-Agent: …Host: …Content-type: text/xmlContent-length: ..
<?xml version=“1.0”?><methodCall><methodName>Circle_Area</methodName><params><param><value><double>12.2</double></value><param><params></methodCall>
![Page 23: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/23.jpg)
Reply message
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value><i4>1</i4></value><value><i4>1</i4></value>
</param>
</params>
</methodResponse>
![Page 24: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/24.jpg)
Fault message<?xml version="1.0"?><methodResponse>
<fault><value>
<struct><member>
<name>faultCode</name><value><int>4</int></value><value><int>4</int></value></member>
<member><name>faultString</name><value><string>Too many parameters.</string></value></member>
</struct></value>
</fault></methodResponse>
![Page 25: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/25.jpg)
JSON-RPC 2.0• JSON-RPC is a stateless, transport agnostic, light-weight
remote procedure call (RPC) protocol• Much like XML-RPC
• No formal grammar• Definition of request object and reply object• Definition of request object and reply object
• New feature: batch requests, notification
![Page 26: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/26.jpg)
Some example --> {"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1}<-- {"jsonrpc": "2.0", "result": 19, "id": 1}
-->{"jsonrpc": "2.0", "method": "subtract", "params": [23, 42], "id": 2}<-- {"jsonrpc": "2.0", "result": -19, "id": 2}
-->{"jsonrpc": "2.0", "method": "subtract", "params": {"subtrahend": 23, "minuend": 42}, "id": 3}<-- {"jsonrpc": "2.0", "result": 19, "id": 3}
--> {"jsonrpc": "2.0", "method": "subtract", "params": {"minuend": 42, "subtrahend": 23}, "id": 4}<-- {"jsonrpc": "2.0", "result": 19, "id": 4}
![Page 27: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/27.jpg)
JSON-RPC call batch --> [
{"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"},{"jsonrpc": "2.0", "method": "notify_hello", "params": [7]},{"jsonrpc": "2.0", "method": "subtract", "params": [42,23], "id": "2"},{"foo": "boo"},{"jsonrpc": "2.0", "method": "foo.get", "params": {"name": "myself"}, "id": "5"},{"jsonrpc": "2.0", "method": "get_data", "id": "9"} {"jsonrpc": "2.0", "method": "get_data", "id": "9"} ]<-- [{"jsonrpc": "2.0", "result": 7, "id": "1"},{"jsonrpc": "2.0", "result": 19, "id": "2"},{"jsonrpc": "2.0", "error": {"code": -32600, "message": "InvalidRequest."}, "id": null},{"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method notfound."}, "id": "5"},{"jsonrpc": "2.0", "result": ["hello", 5], "id": "9"}]
![Page 28: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/28.jpg)
JSONP (JSON with Padding)
GET
f(JSON data)
….<javasxcript scr=xxx&callback=f>….
Used in JavaScriptAllows to overcome the cross-domain problemUses a callback function
![Page 29: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/29.jpg)
REST• Method calls are mapped to HTTP request (Get, Post)• Method name is a parameter of the call• Reply is usually formatted as JSON or XML
![Page 30: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/30.jpg)
SOAP• It’s by far the most verbose protocol• Service is described in WSDL file • Messages as XML documents formatted according to a
specific schema
![Page 31: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/31.jpg)
Tool utili per il debugging
![Page 32: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/32.jpg)
RCP over Internet: example
…Features
geolookup conditions forecast
types= JSON, XML
http://api.wunderground.com/api/http://api.wunderground.com/api/http://api.wunderground.com/api/http://api.wunderground.com/api/KEYKEYKEYKEY////FEATUREFEATUREFEATUREFEATURE/[/[/[/[FEATUREFEATUREFEATUREFEATURE…]/q/…]/q/…]/q/…]/q/QUERYQUERYQUERYQUERY....FORMATFORMATFORMATFORMAT
![Page 33: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/33.jpg)
Examplehttp://api.wunderground.com/api/[API_KEY]/conditions/q/rome.json
….
location ID
http://api.wunderground.com/api/[API_KEY]/conditions/q/rome.json?callback=f
JSONP
![Page 34: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/34.jpg)
Example of XML replyhttp://api.wunderground.com/api/[APIKEY]/conditions/q/zmw:00000.1.16240.xml
![Page 35: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/35.jpg)
Interoperability
Chrome Developer tool
![Page 36: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/36.jpg)
Static call • Using JS src you can “make a call” and display results on
the screen•
![Page 37: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/37.jpg)
Static call
![Page 38: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/38.jpg)
Dynamic Call
![Page 39: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/39.jpg)
Dynamic call
1. Dynamically create a HTML element and append in the head section
2. Call the URL with callback function
![Page 40: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/40.jpg)
Dynamic call
Show the current temperature on the screen• Show the current temperature on the screen
![Page 41: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/41.jpg)
Using jQuery
![Page 42: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/42.jpg)
Additional example
![Page 43: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/43.jpg)
Additional example
![Page 44: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/44.jpg)
Example: Geocoding API
![Page 45: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/45.jpg)
Example: Geocoding API (json)
![Page 46: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/46.jpg)
Example: Geocoding API (xml)
![Page 47: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/47.jpg)
Example: reverse Geocoding (json)
![Page 48: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/48.jpg)
Example: Reverse geocoding (xml)
![Page 49: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/49.jpg)
Google’s JavaScript API (vers. 3)
![Page 50: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/50.jpg)
Example
![Page 51: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/51.jpg)
Example:
![Page 52: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/52.jpg)
Geolocation in HTML5
![Page 53: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/53.jpg)
Example: Flickr ®
![Page 54: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/54.jpg)
Flickr: request, reply message format
http://api.flickr.com/services/xmlrpc/
http://api.flickr.com/services/soap/
WEB-API
http://api.flickr.com/services/rest/
![Page 55: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/55.jpg)
Example: rest call
![Page 56: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/56.jpg)
Example
• Reply is wrapped through jsonFlickrApi callback name• To avoid this, set nojsoncallback=1 option
json format
![Page 57: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/57.jpg)
Asynchronous RPC: AJAX
Sicurezza:Cross domain non è consentito
![Page 58: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/58.jpg)
Example: using AJAX
![Page 59: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/59.jpg)
Example: using AJAX
![Page 60: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/60.jpg)
Example: searching photos
![Page 61: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/61.jpg)
Example: searching photos
![Page 62: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/62.jpg)
Example: searching data
Key photo contains photo details
![Page 63: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/63.jpg)
Example: searching photo
Every photo has a link[mstzb] defines the size
![Page 64: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/64.jpg)
Example: searching photos
![Page 65: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/65.jpg)
Other example
http://api.wordreference.com/{api_version}/{API_key}/{dictionary}/{term}
http://api.wordreference.com/{api_version}/{API_key}/JSON/{dictionary}/{term}
![Page 66: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/66.jpg)
Example
![Page 67: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/67.jpg)
Example
![Page 68: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/68.jpg)
Example: Twitter API
![Page 69: RPC OVER INTERNETberaldi/PSD_013/JS.pdf · JSON-RPC 2.0 • JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol • Much like XML-RPC •](https://reader036.fdocuments.in/reader036/viewer/2022062506/5ee25c1aad6a402d666cddc3/html5/thumbnails/69.jpg)
Exercise
• Write a simple JS program for the TTT game• Hint:
• use a table for button formatting• Use a single handler to make modification