KEMBAR78
Java Script Based Client Server Webapps 2 | PPT
Interoperable JavaScript-Based Client/Server Web Applications Kris Zyp
 
Overview Service oriented client/server web application Tools of interoperability REST Defines interoperable web architecture JSON Referencing/JSON Hyperlinking JSON Schema JSONQuery Comet - Bayeux & REST Channels Consistent programming and data model on client and server Dojo & Persevere - see it in action!
SOA-Based Client/Server Model Distribution of Processing User response latency Programming model Vector of attack State management on server vs client Offline capabilities Interoperability
Service Oriented Architecture on the Web Web Service Provider CS Web Client Web Client Desktop Client Methods Methods Methods
REST Basics It is an architectural style not a format or API The web has leveraged REST Web applications can choose to leverage the benefits of REST or not Implications for how we develop the internal architecture http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
REST Basics The REST Style Constraints Client-Server Stateless Cacheable Uniform Interface Layered Code-On-Demand http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
Interoperability Basics HTTP REST GET - query and get by id PUT - update an object POST - create an object DELETE - delete an object
Uniform Interface One interface for all applications Manipulation of resources, standard methods: PUT, POST, DELETE From a single URL data can be discovered via hyperlinks Data can be accessed without out-of-band API documentation
Standard Conventions Objects/records accessible by /table/id /Product/12 GET, PUT, and DELETE this resource Sub object URLs determined by object identity properties GET /Product/ [{“id”:”11”, “name”:”Dérailleur”},  {“id”:”12”, “name”:”Handle Bar”}]
HTTP/REST + JSON = Database interaction for the web REST Architecture recommends UI - data separation On the wire: On-demand code Data (resource representations)
Tools/Frameworks Client Side Dojo Jester Persevere Futon Server Side CouchDB Persevere SimpleDB ...
The post-ORM realm
Referencing Hyperlinking + JSON Cyclic Multiple references Cross-message references Cross-site references http://www.sitepen.com/blog/2008/06/17/json-referencing-in-dojo/
JSON Referencing Example { “ name”:”Kris Zyp”, “id”:”kriszyp”, “ children”:[ {“id”:”jennikazyp”,“name”:”Jennika Zyp”} ], “ spouse”:{ “ name”:”Nicole Zyp”, “ spouse”:{“$ref”:”kriszyp”}, “ children”:[ {“$ref”:”jennikazyp”} ] } } }
JSON Referencing Example (Fragments and Remote) { “ name”:”Kris Zyp”, “ children”:[ {“name”:”Jennika Zyp”} ], “ spouse”:{“name”:”Nicole Zyp”, “ spouse”:{“$ref”:”#”}, “ children”:{“$ref”:”#children”}}, “ friends”:[   {“$ref”:” http://anothersite.com/jesse ”} ] }
Dojo Data
ServiceStore Adapts web services to dojo.data API Plug services directly into widgets Supports lazy loading
JsonRestStore Full Read/Write API Create,  Read/Query,  Update Delete Standards Based (HTTP compliant)
Read/Write REST Services REST Services can plugin for full read/write ORM-style functionality: GET - query and get by id PUT - update an object POST - create an object DELETE - delete an object
JsonRestStore Lazy loading JSON Referencing Transactional Offline Support
Persevere Built for Client-side MVC, UI - Data separation JSONQuery/JSONPath JSON Referencing Comet Live Data Notifications JSON Schema with evolutionary constraints JSON-RPC Built-in Security Standards based REST interface http://sitepen.com/labs/persevere.php
JSON Schema schema: { "description":"A person",  "type":"object",  "properties":  { "name": {"type":"string"},  "age" : {"type":"integer","maximum":125} } } instance: { “ name”: ”Kris”, “ age”: 30 }
JSON Schema Schema: { "description":"A person", "type":"object", "properties":{ "name": {"type":"string"},  "age": { "type":["integer",”string”], “ friends”: { “ type”:”array”, “ items”:{“type”:”object”} } } } } instance: { “ name”:”Kris”, “ age”:”old”, “ friends”:[{“name”:”Nikki”}] }
JSON Schema Schema: { “ id”:”marriedperson”, "description":"A married person",  "extends": {“$ref”:”marriedperson”},  "properties": {"spouse": {"$ref":"marriedperson"}} } instance: { “ name”:”Kris”, “ age”:”old”, “ friends”:[{“name”:”Bill”}], “ spouse”:{$”ref”:”nikki”} }
Schemas DB defined schema - Relational DBs Schema free – Document DBs Evolutionary schema - Persevere
JSON Schema based evolutionary schema Start without a schema Add constraints as application evolves
JSON Schema driven UI Start with schema http://javascript.neyric.com/inputex/examples/json-schema2.html http://javascript.neyric.com/inputex/examples/base-schema.js
JSON Schema Support Validate JSON/object-style data Enforce data constraints on the client side in JsonRestStore Document interfaces and provide API contracts Can be used in SMDs Generate schema-driven UI with generic clients
Server side JavaScript + web storage http://sitepen.com/labs/persevere.php "schema":{ “ name”:”Friend”, “ properties”:{ “ firstName”:{“type”:”string”}, “age”:{“type”:”integer”}, } "staticCreateMethod":function(arg1){ var friend = new Friend(); friend.age = 0; }, "prototype":{ “ myMethod”:function(){ return this.firstName + ‘ ‘ + this.lastName; } } "extends":{"$ref":"../Person"} }
JSON Schema + JavaScript Adds typing/classes to JavaScript Unobtrusive Flexible Dynamic Portable Can be integrated with data storage
JSON-RPC RPC in JSON Widely adopted Example: { “id”:”1”, “method”:”addAge”, “params”:[“3”] }
ServerJS Interoperable JS Modules Defines module loader via “require” function Various modules in the works File I/O HTTP request handling interface Promises
Querying Web-safe portability important SQL extremely hard to make secure and too complicated in the browser JSONPath JavaScript-style syntax Language agnostic Easy to secure http://goessner.net/articles/JsonPath/
JSONPath http://goessner.net/articles/JsonPath/ XPath like query language for JSON Filters - [?expr] Properties/paths (like JS) - .prop Recursive descent - ..prop Slice operator – [3:10:2] Union operator - [3,4,5]
JSONPath querying in requests JSONPath + REST URLs = Web querying /Table/ - All the objects in a table /Table/[?@.price < 10] – all items with a price under $10 /Table/..name – A list of the name property values /Table/.length – A count of the items in the table
JSONQuery http://www.sitepen.com/blog/2008/07/16/jsonquery-data-querying-beyond-jsonpath/ Lenient Syntax - ?price<10 Sorting - [/price, \rating] Mapping - [=firstName+' '+lastName] Wildcarding [?description='*fun*'] Recursive object filter - ..[?name='Bar'] Example URL: /Table/[?price<10] [={name:name, rating: rating}] [\rating]
Push/Comet Open Protocols for Comet Bayeux XMPP REST Channels
Bayeux Service Negotiation Publish/Subscribe Protocol
Live Data Notifications with REST Channels http://cometdaily.com/2008/05/13/http-channels-2/
REST Channels Push Protocol to augment REST architectural style Based on HTTP standard semantics
HTTP Channels (REST Channels over HTTP) HTTP/1.1 200 OK X-Event: PUT Content-Location: /foo/bar New content of /foo/bar
REST Channels in JSON Accompanied by Demo { “ event”: “put” “ source”: “/foo/bar” “ content”: “New content of /foo/bar” }
Offline + REST REST + Thin Server = Easy Offline Going offline requires a “capable” client Dojo’s support for Offline SOA Applications Accompanied by Demo
Security in SOA Security clearly distinct from UI code Assume users are directly accessing services Improved isolation of security
Security with web accessible data storage Typical databases behind the application Web DBs are directly accessible User authorization becomes integrated with data Allows separation of application and security concerns
Transactions
REST/Ajax JSON Databases Standards based interoperable web database interaction More direct, cleaner model for creating web applications Leverage the web's REST model Caching, proxying, etc.
Persevere JSONQuery/JSONPath JSON Referencing Comet Live Data Notifications JSON Schema with evolutionary constraints JSON-RPC Built-in Security Standards based REST interface http://sitepen.com/labs/persevere.php
Characteristics of good client/server application Clean client/server interface Interchangeability Increased presentation on the client Business logic on the server http://www.sitepen.com/blog/2008/07/18/clientserver-model-on-the-web/
Dojo’s SOA Service auto configuration Integration into Dojo Data model Full REST interaction support Comet and Offline capabilities All based on standards, easy to switch to something else
REST/ Ajax databases Develop for the future
The Open Web is more than just licensing GPL LGPL BSD
Web Application Development Technical Advice Support Services Training Simple.  Fast.  Extraordinary. For clients including: Providing: http://sitepen.com/

Java Script Based Client Server Webapps 2

  • 1.
  • 2.
  • 3.
    Overview Service orientedclient/server web application Tools of interoperability REST Defines interoperable web architecture JSON Referencing/JSON Hyperlinking JSON Schema JSONQuery Comet - Bayeux & REST Channels Consistent programming and data model on client and server Dojo & Persevere - see it in action!
  • 4.
    SOA-Based Client/Server ModelDistribution of Processing User response latency Programming model Vector of attack State management on server vs client Offline capabilities Interoperability
  • 5.
    Service Oriented Architectureon the Web Web Service Provider CS Web Client Web Client Desktop Client Methods Methods Methods
  • 6.
    REST Basics Itis an architectural style not a format or API The web has leveraged REST Web applications can choose to leverage the benefits of REST or not Implications for how we develop the internal architecture http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
  • 7.
    REST Basics TheREST Style Constraints Client-Server Stateless Cacheable Uniform Interface Layered Code-On-Demand http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
  • 8.
    Interoperability Basics HTTPREST GET - query and get by id PUT - update an object POST - create an object DELETE - delete an object
  • 9.
    Uniform Interface Oneinterface for all applications Manipulation of resources, standard methods: PUT, POST, DELETE From a single URL data can be discovered via hyperlinks Data can be accessed without out-of-band API documentation
  • 10.
    Standard Conventions Objects/recordsaccessible by /table/id /Product/12 GET, PUT, and DELETE this resource Sub object URLs determined by object identity properties GET /Product/ [{“id”:”11”, “name”:”Dérailleur”}, {“id”:”12”, “name”:”Handle Bar”}]
  • 11.
    HTTP/REST + JSON= Database interaction for the web REST Architecture recommends UI - data separation On the wire: On-demand code Data (resource representations)
  • 12.
    Tools/Frameworks Client SideDojo Jester Persevere Futon Server Side CouchDB Persevere SimpleDB ...
  • 13.
  • 14.
    Referencing Hyperlinking +JSON Cyclic Multiple references Cross-message references Cross-site references http://www.sitepen.com/blog/2008/06/17/json-referencing-in-dojo/
  • 15.
    JSON Referencing Example{ “ name”:”Kris Zyp”, “id”:”kriszyp”, “ children”:[ {“id”:”jennikazyp”,“name”:”Jennika Zyp”} ], “ spouse”:{ “ name”:”Nicole Zyp”, “ spouse”:{“$ref”:”kriszyp”}, “ children”:[ {“$ref”:”jennikazyp”} ] } } }
  • 16.
    JSON Referencing Example(Fragments and Remote) { “ name”:”Kris Zyp”, “ children”:[ {“name”:”Jennika Zyp”} ], “ spouse”:{“name”:”Nicole Zyp”, “ spouse”:{“$ref”:”#”}, “ children”:{“$ref”:”#children”}}, “ friends”:[ {“$ref”:” http://anothersite.com/jesse ”} ] }
  • 17.
  • 18.
    ServiceStore Adapts webservices to dojo.data API Plug services directly into widgets Supports lazy loading
  • 19.
    JsonRestStore Full Read/WriteAPI Create, Read/Query, Update Delete Standards Based (HTTP compliant)
  • 20.
    Read/Write REST ServicesREST Services can plugin for full read/write ORM-style functionality: GET - query and get by id PUT - update an object POST - create an object DELETE - delete an object
  • 21.
    JsonRestStore Lazy loadingJSON Referencing Transactional Offline Support
  • 22.
    Persevere Built forClient-side MVC, UI - Data separation JSONQuery/JSONPath JSON Referencing Comet Live Data Notifications JSON Schema with evolutionary constraints JSON-RPC Built-in Security Standards based REST interface http://sitepen.com/labs/persevere.php
  • 23.
    JSON Schema schema:{ &quot;description&quot;:&quot;A person&quot;, &quot;type&quot;:&quot;object&quot;, &quot;properties&quot;: { &quot;name&quot;: {&quot;type&quot;:&quot;string&quot;}, &quot;age&quot; : {&quot;type&quot;:&quot;integer&quot;,&quot;maximum&quot;:125} } } instance: { “ name”: ”Kris”, “ age”: 30 }
  • 24.
    JSON Schema Schema:{ &quot;description&quot;:&quot;A person&quot;, &quot;type&quot;:&quot;object&quot;, &quot;properties&quot;:{ &quot;name&quot;: {&quot;type&quot;:&quot;string&quot;}, &quot;age&quot;: { &quot;type&quot;:[&quot;integer&quot;,”string”], “ friends”: { “ type”:”array”, “ items”:{“type”:”object”} } } } } instance: { “ name”:”Kris”, “ age”:”old”, “ friends”:[{“name”:”Nikki”}] }
  • 25.
    JSON Schema Schema:{ “ id”:”marriedperson”, &quot;description&quot;:&quot;A married person&quot;, &quot;extends&quot;: {“$ref”:”marriedperson”}, &quot;properties&quot;: {&quot;spouse&quot;: {&quot;$ref&quot;:&quot;marriedperson&quot;}} } instance: { “ name”:”Kris”, “ age”:”old”, “ friends”:[{“name”:”Bill”}], “ spouse”:{$”ref”:”nikki”} }
  • 26.
    Schemas DB definedschema - Relational DBs Schema free – Document DBs Evolutionary schema - Persevere
  • 27.
    JSON Schema basedevolutionary schema Start without a schema Add constraints as application evolves
  • 28.
    JSON Schema drivenUI Start with schema http://javascript.neyric.com/inputex/examples/json-schema2.html http://javascript.neyric.com/inputex/examples/base-schema.js
  • 29.
    JSON Schema SupportValidate JSON/object-style data Enforce data constraints on the client side in JsonRestStore Document interfaces and provide API contracts Can be used in SMDs Generate schema-driven UI with generic clients
  • 30.
    Server side JavaScript+ web storage http://sitepen.com/labs/persevere.php &quot;schema&quot;:{ “ name”:”Friend”, “ properties”:{ “ firstName”:{“type”:”string”}, “age”:{“type”:”integer”}, } &quot;staticCreateMethod&quot;:function(arg1){ var friend = new Friend(); friend.age = 0; }, &quot;prototype&quot;:{ “ myMethod”:function(){ return this.firstName + ‘ ‘ + this.lastName; } } &quot;extends&quot;:{&quot;$ref&quot;:&quot;../Person&quot;} }
  • 31.
    JSON Schema +JavaScript Adds typing/classes to JavaScript Unobtrusive Flexible Dynamic Portable Can be integrated with data storage
  • 32.
    JSON-RPC RPC inJSON Widely adopted Example: { “id”:”1”, “method”:”addAge”, “params”:[“3”] }
  • 33.
    ServerJS Interoperable JSModules Defines module loader via “require” function Various modules in the works File I/O HTTP request handling interface Promises
  • 34.
    Querying Web-safe portabilityimportant SQL extremely hard to make secure and too complicated in the browser JSONPath JavaScript-style syntax Language agnostic Easy to secure http://goessner.net/articles/JsonPath/
  • 35.
    JSONPath http://goessner.net/articles/JsonPath/ XPathlike query language for JSON Filters - [?expr] Properties/paths (like JS) - .prop Recursive descent - ..prop Slice operator – [3:10:2] Union operator - [3,4,5]
  • 36.
    JSONPath querying inrequests JSONPath + REST URLs = Web querying /Table/ - All the objects in a table /Table/[?@.price < 10] – all items with a price under $10 /Table/..name – A list of the name property values /Table/.length – A count of the items in the table
  • 37.
    JSONQuery http://www.sitepen.com/blog/2008/07/16/jsonquery-data-querying-beyond-jsonpath/ LenientSyntax - ?price<10 Sorting - [/price, \rating] Mapping - [=firstName+' '+lastName] Wildcarding [?description='*fun*'] Recursive object filter - ..[?name='Bar'] Example URL: /Table/[?price<10] [={name:name, rating: rating}] [\rating]
  • 38.
    Push/Comet Open Protocolsfor Comet Bayeux XMPP REST Channels
  • 39.
    Bayeux Service NegotiationPublish/Subscribe Protocol
  • 40.
    Live Data Notificationswith REST Channels http://cometdaily.com/2008/05/13/http-channels-2/
  • 41.
    REST Channels PushProtocol to augment REST architectural style Based on HTTP standard semantics
  • 42.
    HTTP Channels (RESTChannels over HTTP) HTTP/1.1 200 OK X-Event: PUT Content-Location: /foo/bar New content of /foo/bar
  • 43.
    REST Channels inJSON Accompanied by Demo { “ event”: “put” “ source”: “/foo/bar” “ content”: “New content of /foo/bar” }
  • 44.
    Offline + RESTREST + Thin Server = Easy Offline Going offline requires a “capable” client Dojo’s support for Offline SOA Applications Accompanied by Demo
  • 45.
    Security in SOASecurity clearly distinct from UI code Assume users are directly accessing services Improved isolation of security
  • 46.
    Security with webaccessible data storage Typical databases behind the application Web DBs are directly accessible User authorization becomes integrated with data Allows separation of application and security concerns
  • 47.
  • 48.
    REST/Ajax JSON DatabasesStandards based interoperable web database interaction More direct, cleaner model for creating web applications Leverage the web's REST model Caching, proxying, etc.
  • 49.
    Persevere JSONQuery/JSONPath JSONReferencing Comet Live Data Notifications JSON Schema with evolutionary constraints JSON-RPC Built-in Security Standards based REST interface http://sitepen.com/labs/persevere.php
  • 50.
    Characteristics of goodclient/server application Clean client/server interface Interchangeability Increased presentation on the client Business logic on the server http://www.sitepen.com/blog/2008/07/18/clientserver-model-on-the-web/
  • 51.
    Dojo’s SOA Serviceauto configuration Integration into Dojo Data model Full REST interaction support Comet and Offline capabilities All based on standards, easy to switch to something else
  • 52.
    REST/ Ajax databasesDevelop for the future
  • 53.
    The Open Webis more than just licensing GPL LGPL BSD
  • 54.
    Web Application DevelopmentTechnical Advice Support Services Training Simple. Fast. Extraordinary. For clients including: Providing: http://sitepen.com/

Editor's Notes

  • #3 SOA on the web, architecture and benefits
  • #12 Working in the post-ORM realmData could be in native object storageData could in relational, but ORM’ed to objectsData storage technology agnosticNon-relational storage Schemas may or may not be appliedLook at this in Persistent Computing on the web presentationDo DemoInstall PersevereCreate TableCreate an objectModify an objectDo a query
  • #24 Analogous to gradual typingBegin prototyping with no schemaSchema-free DB is extremely beneficial for prototyping in early stage agile developmentGradually adding constraints as the application evolvesAnalogous to how we do evolve in user requirements with agile devLanguage and storage agnostic data definitionsUIs can use schemas to auto-generate forms and widgetsUI can auto-update based on schema changesAnother form of rapid prototyping (reverse direction, starting with schemas)Flexible prototyping approachAll can be done with Persevere
  • #25 Persevere includes class definition for each tableTable objects are class instancesPrototype methodsFunction storage capableWorks in conjunction with SchemasJSON-RPC interaction with object methodsAccompanied by DemoSet up PersevereStoreCreate itemModify itemConnect to a widgetShow demo from consoleShow demo from console
  • #31 Any Bayeux client should be able to connect to any Bayeux server and communicatePubSub protocolService/Transport Advertising and NegotiationDefault format for transportsSemantics include:PublishSubscribeDeliverREST Channels provide data modification notifications using HTTP/REST semanticsMinimal extension of HTTP standardsCompatible upgrade to RESTHTTP/MIME or JSON formatEnables live views of data with virtually no extra codingAccompanied by DemoREST Channels provide data modification notifications using HTTP/REST semanticsMinimal extension of HTTP standardsCompatible upgrade to RESTHTTP/MIME or JSON formatEnables live views of data with virtually no extra coding
  • #32 Accompanied by DemoService oriented architecture with thin server architecture makes building offline applications much easierdojox.rpc.OfflineRest - Dojo module that can automatically add offline support for apps that do server interaction through JsonRestStoreData changes are stored/cached locally until network connectivity is available.Accompanied by Demo
  • #37 Easy to use, clearly defined web APIOne could create a new UI for the application without barrierPresentation code is executed on the client, business/application logic occurs on the backendPresentation state on the clientLess load on the server, more scalableREST Channels provide data modification notifications using HTTP/REST semanticsMinimal extension of HTTP standardsCompatible upgrade to RESTHTTP/MIME or JSON formatEnables live views of data with virtually no extra coding