JSON Web Databases Applied JSON: HTTP REST, Ajax databases and beyond Kris Zyp
 
HTTP/REST + JSON = Database interaction for the web
Overview Interoperability Basics Tools/Frameworks Beyond simple CRUD
Interoperability Basics HTTP REST GET - query and get by id PUT - update an object POST - create an object DELETE - delete an object
Tools/Frameworks Client Side Persevere Jester Dojo Server Side ActiveResource CouchDB Persevere GrassyKnoll ...
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”}]
The post-ORM realm
Schemas DB defined schema - ActiveRecord Schema free - CouchDB
Evolutionary Schema: Persevere
JSON Schema based evolutionary schema Start without a schema Add constraints as application evolves
JSON Schema schema: {"description":"A person", "type":"object", "properties": {"name": {"type":"string"}, "age" : {"type":"integer", "maximum":125}} } instance: {“name”:”Kris”, “ age”:30}
JSON Schema driven UI Start with schema and simple form
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 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
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]
JSON 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 http://www.sitepen.com/blog/2008/07/16/jsonquery-data-querying-beyond-jsonpath/ { “ name”:”Kris Zyp”, “ id”:”kriszyp”, “children”:[{“id”:”jennikazyp”,“name”:”Jennika Zyp”}], “ spouse”:{ “ name”:”Nicole Zyp”, “spouse”:{“$ref”:”kriszyp”}, “ children”:[{“$ref”:”jennikazyp”}] } }
JSON Referencing http://www.sitepen.com/blog/2008/07/16/jsonquery-data-querying-beyond-jsonpath/ { “ name”:”Kris Zyp”, “children”:[{“name”:”Jennika Zyp”}], “ spouse”:{ “ name”:”Nicole Zyp”, “spouse”:{“$ref”:”#”}, “ children”:{“$ref”:”#.children”} } }
JSON Referencing http://www.sitepen.com/blog/2008/07/16/jsonquery-data-querying-beyond-jsonpath/ { “ name”:”Kris Zyp”, “ id”:”kriszyp”, “children”:[{“name”:”Jennika Zyp”}], “ friends”:[{“$ref”:”jesse#.spouse”}] }
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;} }
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
Security with Persevere Data-centric Capability-based Logic/code based security possible as well
Transactions
Live Data Notifications with REST Channels http://cometdaily.com/2008/05/13/http-channels-2/
Other Features File storage/alternate resource representations Utilize existing SQL tables SMD support Class/Table Inheritance
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
REST/ Ajax databases Develop for the future
 

RESTful JSON web databases