More Related Content
PDF
ふぉとぶらり+LODAC -iPhoneアプリでのSPARQLでの活用事例- PPTX
KEY
PPTX
PPTX
PDF
Beginning Java EE 6 勉強会(7) #bje_study PDF
MyNA JPUG study 20160220-postgresql-json-datatype PDF
Viewers also liked
PDF
My Interview with Healthy code Magazine: Future of Android Design PPTX
Enterprise-приложения: Web против Objective C PDF
PPTX
iPhone Development For Experienced Web Developers PDF
KEY
PDF
PDF
Iphone programming: Objective c PPTX
KEY
Objective-C Crash Course for Web Developers PPTX
PDF
PDF
PDF
Canvas دورة باللغة العربية PPTX
Similar to JSON Based Web Services
PDF
PPTX
Deep dive into oss written in swift PPTX
Deep dive into oss written in swift PPTX
Androidで使えるJSON-Javaライブラリ PPTX
PPT
PDF
PDF
PDF
PDF
PDF
PDF
PDF
PDF
Hypermedia: The Missing Element to Building Adaptable Web APIs in Rails (増補日本語版) PDF
RFC7951(JSON Encoding of Data Modeled with YANG)の勉強資料 PDF
PDF
Swift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswift PDF
Movable Type 6の新機能 Data APIの活用法 PDF
PDF
More from Toru Yamaguchi
PDF
PDF
OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015 PDF
Mobage Connect と Identity 関連技術への取り組み - OpenID Summit Tokyo 2015 PPTX
PPTX
PPTX
PDF
How to bake delicious cookie (RESTful Meetup #03) PDF
PPTX
ngCore engine for mobage platform PPT
PDF
mbga Open Platform and Perl PDF
Inside mbga Open Platform API architecture PDF
Introduction OpenID Authentication 2.0 Revival PDF
PDF
Introduction OpenID Authentication 2.0 PDF
PPT
PPT
PDF
The Security of OpenID Authentication 2.0 PPT
Customization of DBIC::Schema::Loader JSON Based Web Services
- 1.
- 2.
- 3.
JSON Pointer とは
•XML で言う所の XPath に相当するもの
• Spec
• http://tools.ietf.org/html/draft-ietf-
appsawg-json-pointer-04
- 4.
JSON Pointer のABNF
json-pointer = *( "/" reference-token )
reference-token = *( unescaped / escaped )
unescaped = %x00-2E / %x30-7D / %x7F-10FFFF
escaped = "~" ( "0" / "1" )
- 5.
JSON Pointer とObject
Access
JSON Pointer Object Access
obj
/ obj[""]
/foo obj["foo"]
/0 obj[0]
/foo/2 obj["foo"][2]
/0/bar obj[0]["bar"]
- 6.
Example (1)
JSON Document JSON Pointer
{
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"ij": 5,
"k"l": 6,
" ": 7,
"m~n": 8
}
- 7.
Example (2)
JSON Document JSON Pointer
{
"foo": ["bar", "baz"],
"": 0,
"a/b": 1, // the whole document
"c%d": 2, json_pointer(doc, "")
"e^f": 3,
"g|h": 4,
"ij": 5,
"k"l": 6,
" ": 7,
"m~n": 8
}
- 8.
Example (3)
JSON Document JSON Pointer
{
"foo": ["bar", "baz"],
"": 0,
"a/b": 1, json_pointer(doc, "/foo")
"c%d": 2,
"e^f": 3,
"g|h": 4,
"ij": 5,
"k"l": 6,
" ": 7,
"m~n": 8
}
- 9.
Example (4)
JSON Document JSON Pointer
{
"foo": ["bar", "baz"],
"": 0,
"a/b": 1, json_pointer(doc, "/foo/0")
"c%d": 2,
"e^f": 3,
"g|h": 4,
"ij": 5,
"k"l": 6,
" ": 7,
"m~n": 8
}
- 10.
Example (5)
JSON Document JSON Pointer
{
"foo": ["bar", "baz"],
"": 0,
"a/b": 1, json_pointer(doc, "/")
"c%d": 2,
"e^f": 3,
"g|h": 4,
"ij": 5,
"k"l": 6,
" ": 7,
"m~n": 8
}
- 11.
Example (5)
JSON Document JSON Pointer
{
"foo": ["bar", "baz"],
"": 0,
"a/b": 1, // escaped "/" as "~1"
"c%d": 2, json_pointer(doc, "/a~1b")
"e^f": 3,
"g|h": 4,
"ij": 5,
"k"l": 6,
" ": 7,
"m~n": 8
}
- 12.
Example (6)
JSON Document JSON Pointer
{
"foo": ["bar", "baz"],
"": 0,
"a/b": 1, // slash and one space
"c%d": 2, json_pointer(doc, "/ ")
"e^f": 3,
"g|h": 4,
"ij": 5,
"k"l": 6,
" ": 7,
"m~n": 8
}
- 13.
Example (5)
JSON Document JSON Pointer
{
"foo": ["bar", "baz"],
"": 0,
"a/b": 1, // escaped "~" as "~0"
"c%d": 2, json_pointer(doc, "/m~0n")
"e^f": 3,
"g|h": 4,
"ij": 5,
"k"l": 6,
" ": 7,
"m~n": 8
}
- 14.
Usage of JSONPointer
• 任意の要素を指し示す事が出来る
• WAF 等でも primitive なデータの探索、取
得に使える (c.f. Mojolicious)
• URI Fragment Identifier Representation (Section
6)
• JSON Document 中の任意の要素を表す
URI を提供出来る (とても大事)
- 15.
- 16.
JSON Patch とは
• Text の差分に対する diff/patch
• JSON の差分に対する JSON Patch
• http://tools.ietf.org/html/draft-ietf-appsawg-json-
patch-05
• 差分を表現する JSON Patch document
• 差分を適用する operation
• MongoDB の operator にちょっと似ている
- 17.
JSON Patch Example
[
{ "op": "test", "path": "/a/b/c", "value": "foo" },
{ "op": "remove", "path": "/a/b/c" },
{ "op": "add", "path": "/a/b/c",
"value": [ "foo", "bar" ] },
{ "op": "replace", "path": "/a/b/c", "value": 42 },
{ "op": "move", "path": "/a/b/c", "to": "/a/b/d" },
{ "op": "copy", "path": "/a/b/c", "to": "/a/b/e" }
]
- 18.
JSON Patch document
• 全体としては配列
• 配列の各要素に operation を表す object が入る
• 各 operation object には op, path というフィールドがある
• op はオペレーション名
• path は適用対象を示す JSON Pointer
• 各 operation object には引数のような key-value が指定さ
れる (value, to)
- 19.
- 20.
Operation - add
JSONPatch Document • JSON Pointer で指定され
た path に value で指定
{
された値を追加する
"op": "add",
"path": "/a/b/c",
"value": ["foo", "bar"] • path は root か存在する
object または array でな
}
ければならない
- 21.
Operation - remove
JSONPatch Document • JSON Pointer で指定され
た target を削除する
{
"op": "remove",
"path": "/a/b/c"
• path は存在する物でな
ければならない
}
- 22.
Operation - replace
JSONPatch Document • JSON Pointer で指定され
た target の値を value で
{
指定された物と置き換
"op": "replace",
える
"path": "/a/b/c",
"value": 42
} • path は存在する物でな
ければならない
- 23.
Operation - move
JSONPatch Document • JSON Pointer で指定された
path を to で指定された場所
{ に移動する
"op": "move",
"path": "/a/b/c", • path の内容を remove
"to": "/a/b/d"
• remove された物を add
}
• to が配列の要素を指定して
いる場合に幾つか制約があ
る
- 24.
Operation - copy
JSONPatch Document • JSON Pointer で指定され
た path を to で指定され
{
た場所に複製する
"op": "copy",
"path": "/a/b/c",
"to": "/a/b/d" • to が配列の要素を指定
している場合に幾つか
}
制約がある
- 25.
Operation - test
JSONPatch Document • JSON Pointer で指定され
た path の値が value で
{
指定された物と一致す
"op": "test",
るか確認する
"path": "/a/b/c",
"value": "foo"
} • 一致しない場合は後
続の operation が実行
されず、即座にエラー
になる
- 26.
Usage of JSONPatch
• Media Type が "application/json-patch" と
なっているので RESTful API で PATCH
メソッドと共に差分適用を表現する
• See RFC 5789
• JSON 相当で記述された設定のプリプロ
セッサなど
- 27.
- 28.
JSON Schema とは
• http://json-schema.org/
• http://tools.ietf.org/html/draft-zyp-json-schema-03
• 暫く動きが見えないけど現在 draft-04 策定
中です
• JSON Document に対して Validation,
Documentation, Hyperlink を与える為のスキー
マ記述形式のこと
- 29.
Validation &
Documentation
• だいぶ syntax が多いので詳細は割愛し
ます:(
• 詳しくは Spec 見て下さい
• 基本的には primitive な値に対して制約
をつける事が出来ます
- 30.
Schema for OAuth2.0 -
Authorization Code Grant
{
"id": "http://schema.example.com/oauth/2.0/authorization_request",
"title": "OAuth 2.0 Authorization Code Grant Response Object",
"properties": {
"code": {
"title": "The authorization code",
"type": "string",
"required": true
},
"state": {
"title": "An opaque value",
"type": "string",
"required": false
}
}
}
- 31.
Explain for theschema
• Authorization Code Grant の Authorization Request の
クエリパラメータについての Schema になっています
• title, description で documentation が可能です
• type で型を指定し、型ごとに指定可能な制約やデ
フォルト値等が指定出来ます
• また type は JSON Pointer を使って任意の JSON
Schema の任意の要素の定義を参照する事が出来ます
- 32.
Hyperlinks
• JSON Documentに Hyperlink を与える為
の JSON Schema の拡張
• 具体的には Schema に対する relation,
endpoint, http method, encoding type,
request property 等を指定出来る
- 33.
Extending Schema forOAuth
2.0 Authorization Code Grant
{
"id": "http://schema.example.com/oauth/2.0/authorization_request",
"title": "OAuth 2.0 Authorization Code Grant Response Object",
"properties": { },
"links": [
{
"title": "Authorization endpoint",
"href": "http://connect.example.com/authorize",
"rel": "create",
"enctype": "application/x-www-form-urlencoded"
"properties": {
"response_type": {}, "client_id": {},
"redirect_uri": {}, "scope": {}, "state": {}
}
}
]
}
- 34.
Explain to thehyper
schema
• https://gist.github.com/3838576 に完全版を書いてみまし
た
• Authorization Response を Resource として、この
Resource を作成する為の Hyperlink を定義しました。
• method, enctype, properties で request format も定義
出来る
• rel で指定可能な物は大体記述可能なので Service
Descriptor のような使い方も出来る
- 35.
- 36.
JSON Pointer
• シンプルなのでデータ取得方法として様々
な所で利用用途がある
• JSON Patch で利用されている
• また JSON Document の内部リンクとして
も利用価値がある
• JSON Schema で利用されている
- 37.
JSON Patch
• RESTfulAPI で PUT メソッドを利用した
Partial Update (要は差分適用) の代わり
に PATCH メソッド + JSON Patch が使
える
• ex) OpenSocial Appdata API
- 38.
JSON Schema
• Validation として様々な言語から再利用可能
• Documentation はツールが整備されれば将来性あり
• http://sk-api-browser.heroku.com/ などの事例もある
• Hyperlink まで利用すると API の記述言語としても使
える
• 応用すれば Facebook Graph API Explorer のように
結果に対して適切なリンクを貼る事も可能
- 39.