Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

RESTful JSON web databases

14,501 views

Published on

Published in: Technology

RESTful JSON web databases

  1. 1. JSON Web Databases <ul><li>Applied JSON: HTTP REST, Ajax databases and beyond </li></ul><ul><li>Kris Zyp </li></ul>
  2. 3. HTTP/REST + JSON = Database interaction for the web
  3. 4. Overview <ul><li>Interoperability Basics </li></ul><ul><li>Tools/Frameworks </li></ul><ul><li>Beyond simple CRUD </li></ul>
  4. 5. Interoperability Basics <ul><li>HTTP REST </li></ul><ul><ul><ul><li>GET - query and get by id </li></ul></ul></ul><ul><ul><ul><li>PUT - update an object </li></ul></ul></ul><ul><ul><ul><li>POST - create an object </li></ul></ul></ul><ul><ul><ul><li>DELETE - delete an object </li></ul></ul></ul>
  5. 6. Tools/Frameworks <ul><li>Client Side </li></ul><ul><ul><li>Persevere </li></ul></ul><ul><ul><li>Jester </li></ul></ul><ul><ul><li>Dojo </li></ul></ul><ul><li>Server Side </li></ul><ul><ul><li>ActiveResource </li></ul></ul><ul><ul><li>CouchDB </li></ul></ul><ul><ul><li>Persevere </li></ul></ul><ul><ul><li>GrassyKnoll </li></ul></ul><ul><ul><li>... </li></ul></ul>
  6. 7. Standard Conventions <ul><li>Objects/records accessible by /table/id </li></ul><ul><ul><li>/Product/12 </li></ul></ul><ul><ul><li>GET, PUT, and DELETE this resource </li></ul></ul><ul><li>Sub object URLs determined by object identity properties </li></ul><ul><ul><li>GET /Product/ [{“id”:”11”, “name”:”Dérailleur”}, {“id”:”12”, “name”:”Handle Bar”}] </li></ul></ul>
  7. 8. The post-ORM realm
  8. 9. Schemas <ul><li>DB defined schema - ActiveRecord </li></ul><ul><li>Schema free - CouchDB </li></ul>
  9. 10. Evolutionary Schema: Persevere
  10. 11. JSON Schema based evolutionary schema Start without a schema Add constraints as application evolves
  11. 12. 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}
  12. 13. JSON Schema driven UI Start with schema and simple form
  13. 14. Querying <ul><li>Web-safe portability important </li></ul><ul><li>SQL extremely hard to make secure and too complicated in the browser </li></ul><ul><li>JSONPath </li></ul><ul><ul><li>JavaScript-style syntax </li></ul></ul><ul><ul><li>Language agnostic </li></ul></ul><ul><ul><li>Easy to secure </li></ul></ul>http://goessner.net/articles/JsonPath/
  14. 15. 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]
  15. 16. JSONPath querying in requests REST URLs + JSONPath = 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
  16. 17. JSONQuery http://www.sitepen.com/blog/2008/07/16/jsonquery-data-querying-beyond-jsonpath/ Lenient Syntax - ?price<10 Sorting - [/price, ating] Mapping - [=firstName+' '+lastName] Wildcarding [?description='*fun*'] Recursive object filter - ..[?name='Bar'] Example URL: /Table/[?price<10] [={name:name, rating: rating}] [ ating]
  17. 18. JSON Referencing <ul><li>Hyperlinking + JSON </li></ul><ul><ul><li>Cyclic </li></ul></ul><ul><ul><li>Multiple references </li></ul></ul><ul><ul><li>Cross-message references </li></ul></ul><ul><ul><li>Cross-site references </li></ul></ul>http://www.sitepen.com/blog/2008/06/17/json-referencing-in-dojo/
  18. 19. JSON Referencing http://www.sitepen.com/blog/2008/07/16/jsonquery-data-querying-beyond-jsonpath/ <ul><li>{ </li></ul><ul><ul><li>“ name”:”Kris Zyp”, </li></ul></ul><ul><ul><li>“ id”:”kriszyp”, “children”:[{“id”:”jennikazyp”,“name”:”Jennika Zyp”}], </li></ul></ul><ul><ul><li>“ spouse”:{ </li></ul></ul><ul><ul><ul><li>“ name”:”Nicole Zyp”, “spouse”:{“$ref”:”kriszyp”}, </li></ul></ul></ul><ul><ul><ul><li>“ children”:[{“$ref”:”jennikazyp”}] </li></ul></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>} </li></ul>
  19. 20. JSON Referencing http://www.sitepen.com/blog/2008/07/16/jsonquery-data-querying-beyond-jsonpath/ <ul><li>{ </li></ul><ul><ul><li>“ name”:”Kris Zyp”, “children”:[{“name”:”Jennika Zyp”}], </li></ul></ul><ul><ul><li>“ spouse”:{ </li></ul></ul><ul><ul><ul><li>“ name”:”Nicole Zyp”, “spouse”:{“$ref”:”#”}, </li></ul></ul></ul><ul><ul><ul><li>“ children”:{“$ref”:”#.children”} </li></ul></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>} </li></ul>
  20. 21. JSON Referencing http://www.sitepen.com/blog/2008/07/16/jsonquery-data-querying-beyond-jsonpath/ <ul><li>{ </li></ul><ul><ul><li>“ name”:”Kris Zyp”, </li></ul></ul><ul><ul><li>“ id”:”kriszyp”, “children”:[{“name”:”Jennika Zyp”}], </li></ul></ul><ul><ul><li>“ friends”:[{“$ref”:”jesse#.spouse”}] </li></ul></ul><ul><li>} </li></ul>
  21. 22. Server side JavaScript + web storage http://sitepen.com/labs/persevere.php <ul><ul><li>&quot;schema&quot;:{ </li></ul></ul><ul><ul><ul><li>“ name”:”Friend”, </li></ul></ul></ul><ul><ul><ul><li>“ properties”:{ </li></ul></ul></ul><ul><ul><ul><ul><li>“ firstName”:{“type”:”string”}, “age”:{“type”:”integer”}, </li></ul></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><li>&quot;staticCreateMethod&quot;:function(arg1){ </li></ul></ul><ul><ul><ul><ul><li>var friend = new Friend; </li></ul></ul></ul></ul><ul><ul><ul><ul><li>friend.age = 0; </li></ul></ul></ul></ul><ul><ul><ul><li>}, </li></ul></ul></ul><ul><ul><li>&quot;prototype&quot;:{ </li></ul></ul><ul><ul><ul><ul><li>“ myMethod”:function(){ </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>return this.firstName + ‘ ‘ + this.lastName; </li></ul></ul></ul></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><li>&quot;extends&quot;:{&quot;$ref&quot;:&quot;../Person&quot;} </li></ul></ul><ul><ul><li>} </li></ul></ul>
  22. 23. Security with web accessible data storage <ul><li>Typical databases behind the application </li></ul><ul><li>Web DBs are directly accessible </li></ul><ul><ul><li>User authorization becomes integrated with data </li></ul></ul><ul><li>Allows separation of application and security concerns </li></ul>
  23. 24. Security with Persevere <ul><li>Data-centric </li></ul><ul><li>Capability-based </li></ul><ul><li>Logic/code based security possible as well </li></ul>
  24. 25. Transactions
  25. 26. Live Data Notifications with REST Channels http://cometdaily.com/2008/05/13/http-channels-2/
  26. 27. Other Features <ul><li>File storage/alternate resource representations </li></ul><ul><li>Utilize existing SQL tables </li></ul><ul><li>SMD support </li></ul><ul><li>Class/Table Inheritance </li></ul>
  27. 28. Persevere <ul><li>JSONQuery/JSONPath </li></ul><ul><li>JSON Referencing </li></ul><ul><li>Comet Live Data Notifications </li></ul><ul><li>JSON Schema with evolutionary constraints </li></ul><ul><li>JSON-RPC </li></ul><ul><li>Built-in Security </li></ul><ul><li>Standards based REST interface </li></ul>http://sitepen.com/labs/persevere.php
  28. 29. REST/ Ajax databases Develop for the future

×