Upload
kriszyp
View
13.299
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
JSON Web Databases
Applied JSON: HTTP REST, Ajax databases and beyondKris Zyp
© SitePen, Inc. 2008. All Rights Reserved
© SitePen, Inc. 2008. All Rights Reserved
HTTP/REST + JSON =Database interaction for
the web
© SitePen, Inc. 2008. All Rights Reserved
Overview
Interoperability BasicsTools/FrameworksBeyond simple CRUD
© SitePen, Inc. 2008. All Rights Reserved
Interoperability Basics
• HTTP RESTGET - query and get by id
PUT - update an object
POST - create an object
DELETE - delete an object
© SitePen, Inc. 2008. All Rights Reserved
Tools/Frameworks
Client SidePersevereJesterDojo
Server SideActiveResourceCouchDBPersevereGrassyKnoll...
© SitePen, Inc. 2008. All Rights Reserved
Standard Conventions
Objects/records accessible by /table/id/Product/12GET, 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”}]
© SitePen, Inc. 2008. All Rights Reserved
The post-ORM realm
© SitePen, Inc. 2008. All Rights Reserved
Schemas
• DB defined schema - ActiveRecord
• Schema free - CouchDB
© SitePen, Inc. 2008. All Rights Reserved
Evolutionary Schema:Persevere
© SitePen, Inc. 2008. All Rights Reserved
JSON Schema based evolutionary schema
Start without a schema
Add constraints
as application
evolves
© SitePen, Inc. 2008. All Rights Reserved
schema:
{"description":"A person",
"type":"object",
"properties":
{"name": {"type":"string"},
"age" : {"type":"integer",
"maximum":125}}
}
instance:
{“name”:”Kris”,
“age”:30}
schema:
{"description":"A person",
"type":"object",
"properties":
{"name": {"type":"string"},
"age" : {"type":"integer",
"maximum":125}}
}
instance:
{“name”:”Kris”,
“age”:30}
JSON Schema
© SitePen, Inc. 2008. All Rights Reserved
JSON Schema driven UIStart with schema
and simple form
© SitePen, Inc. 2008. All Rights Reserved
http://goessner.net/articles/JsonPath/
Querying
Web-safe portability importantSQL extremely hard to make secure and too complicated in the browserJSONPath
JavaScript-style syntaxLanguage agnosticEasy to secure
© SitePen, Inc. 2008. All Rights Reserved
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]
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
© SitePen, Inc. 2008. All Rights Reserved
REST URLs + JSONPath = Web querying
/Table/ - All the objects in a table
/Table/[[email protected] < 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
REST URLs + JSONPath = Web querying
/Table/ - All the objects in a table
/Table/[[email protected] < 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
JSONPath querying in requests
© SitePen, Inc. 2008. All Rights Reserved
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]
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]
JSONQuery
© SitePen, Inc. 2008. All Rights Reserved
http://www.sitepen.com/blog/2008/06/17/json-referencing-in-dojo/
JSON Referencing
Hyperlinking + JSON
• Cyclic
• Multiple references
• Cross-message references
• Cross-site references
© SitePen, Inc. 2008. All Rights Reserved
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”}]
}}
{“name”:”Kris Zyp”,“id”:”kriszyp”,“children”:[{“id”:”jennikazyp”,“name”:”Jennika Zyp”}],“spouse”:{“name”:”Nicole Zyp”,“spouse”:{“$ref”:”kriszyp”},“children”:[{“$ref”:”jennikazyp”}]
}}
JSON Referencing
© SitePen, Inc. 2008. All Rights Reserved
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”}
}}
{“name”:”Kris Zyp”,“children”:[{“name”:”Jennika Zyp”}],“spouse”:{“name”:”Nicole Zyp”,“spouse”:{“$ref”:”#”},“children”:{“$ref”:”#.children”}
}}
JSON Referencing
© SitePen, Inc. 2008. All Rights Reserved
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”}]
}
{“name”:”Kris Zyp”,“id”:”kriszyp”,“children”:[{“name”:”Jennika Zyp”}],“friends”:[{“$ref”:”jesse#.spouse”}]
}
JSON Referencing
© SitePen, Inc. 2008. All Rights Reserved
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"}
}
"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"}
}
Server side JavaScript + web storage
© SitePen, Inc. 2008. All Rights Reserved
Security with web accessible data storageTypical databases behind the applicationWeb DBs are directly accessible
User authorization becomes integrated with dataAllows separation of application and security concerns
© SitePen, Inc. 2008. All Rights Reserved
Security with Persevere
Data-centricCapability-basedLogic/code based security possible as well
© SitePen, Inc. 2008. All Rights Reserved
Transactions
© SitePen, Inc. 2008. All Rights Reserved
Live Data Notifications with REST Channels
http://cometdaily.com/2008/05/13/http-channels-2/
© SitePen, Inc. 2008. All Rights Reserved
Other Features
File storage/alternate resource representationsUtilize existing SQL tablesSMD supportClass/Table Inheritance
© SitePen, Inc. 2008. All Rights Reserved
Persevere
JSONQuery/JSONPathJSON ReferencingComet Live Data NotificationsJSON Schema with evolutionary constraintsJSON-RPCBuilt-in SecurityStandards based REST interface
http://sitepen.com/labs/persevere.php
© SitePen, Inc. 2008. All Rights Reserved
REST/ Ajax databasesDevelop for the future
© SitePen, Inc. 2008. All Rights Reserved