30
JSON Web Databases Applied JSON: HTTP REST, Ajax databases and beyond Kris Zyp

RESTful JSON web databases

  • Upload
    kriszyp

  • View
    13.299

  • Download
    1

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: RESTful JSON web databases

JSON Web Databases

Applied JSON: HTTP REST, Ajax databases and beyondKris Zyp

Page 2: RESTful JSON web databases

© SitePen, Inc. 2008. All Rights Reserved

Page 3: RESTful JSON web databases

© SitePen, Inc. 2008. All Rights Reserved

HTTP/REST + JSON =Database interaction for

the web

Page 4: RESTful JSON web databases

© SitePen, Inc. 2008. All Rights Reserved

Overview

Interoperability BasicsTools/FrameworksBeyond simple CRUD

Page 5: RESTful JSON web databases

© 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

Page 6: RESTful JSON web databases

© SitePen, Inc. 2008. All Rights Reserved

Tools/Frameworks

Client SidePersevereJesterDojo

Server SideActiveResourceCouchDBPersevereGrassyKnoll...

Page 7: RESTful JSON web databases

© 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”}]

Page 8: RESTful JSON web databases

© SitePen, Inc. 2008. All Rights Reserved

The post-ORM realm

Page 9: RESTful JSON web databases

© SitePen, Inc. 2008. All Rights Reserved

Schemas

• DB defined schema - ActiveRecord

• Schema free - CouchDB

Page 10: RESTful JSON web databases

© SitePen, Inc. 2008. All Rights Reserved

Evolutionary Schema:Persevere

Page 11: RESTful JSON web databases

© SitePen, Inc. 2008. All Rights Reserved

JSON Schema based evolutionary schema

Start without a schema

Add constraints

as application

evolves

Page 12: RESTful JSON web databases

© 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

Page 13: RESTful JSON web databases

© SitePen, Inc. 2008. All Rights Reserved

JSON Schema driven UIStart with schema

and simple form

Page 14: RESTful JSON web databases

© 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

Page 15: RESTful JSON web databases

© 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

Page 16: RESTful JSON web databases

© 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

Page 17: RESTful JSON web databases

© 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

Page 18: RESTful JSON web databases

© 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

Page 19: RESTful JSON web databases

© 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

Page 20: RESTful JSON web databases

© 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

Page 21: RESTful JSON web databases

© 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

Page 22: RESTful JSON web databases

© 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

Page 23: RESTful JSON web databases

© 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

Page 24: RESTful JSON web databases

© SitePen, Inc. 2008. All Rights Reserved

Security with Persevere

Data-centricCapability-basedLogic/code based security possible as well

Page 25: RESTful JSON web databases

© SitePen, Inc. 2008. All Rights Reserved

Transactions

Page 26: RESTful JSON web databases

© SitePen, Inc. 2008. All Rights Reserved

Live Data Notifications with REST Channels

http://cometdaily.com/2008/05/13/http-channels-2/

Page 27: RESTful JSON web databases

© SitePen, Inc. 2008. All Rights Reserved

Other Features

File storage/alternate resource representationsUtilize existing SQL tablesSMD supportClass/Table Inheritance

Page 28: RESTful JSON web databases

© 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

Page 29: RESTful JSON web databases

© SitePen, Inc. 2008. All Rights Reserved

REST/ Ajax databasesDevelop for the future

Page 30: RESTful JSON web databases

© SitePen, Inc. 2008. All Rights Reserved