Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
YAPC::Fukuoka 2017 HAKATA
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Takatsugu Shigeta
July 01, 2017
0
1.2k
YAPC::Fukuoka 2017 HAKATA
Web API の未来について GraphQL のことをお話ししました。
Takatsugu Shigeta
July 01, 2017
Tweet
Share
More Decks by Takatsugu Shigeta
See All by Takatsugu Shigeta
Contributing to open source products
comewalk
0
820
MTDDC Meetup KYUSHU 2013
comewalk
1
1.2k
Featured
See All Featured
Code Review Best Practice
trishagee
74
20k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
760
Music & Morning Musume
bryan
47
7.1k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
330
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
0
2.3k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
450
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
79
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.8k
Utilizing Notion as your number one productivity tool
mfonobong
3
220
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
130
Transcript
{ talk(title: "Web API の未来") { title event speaker keywords
} }
{ "talk": { "title": "Web API の未来", "event": "YAPC::Fukuoka 2017",
"speaker": "Takatsugu Shigeta", "keywords": ["API", "GraphQL"] } }
{ speaker(name: "Shigeta") { name elsewhere work } }
{ "speaker": { "name": "シゲタタカツグ", "elsewhere": { "PAUSE": "SHIGETA", "Twitter":
"@comewalk", "GitHub": "@comewalk", "Blog": "https://blog.comewalk.com/" }, "work": { "at": "Six Apart Ltd.", "information": "We are hiring!" } } }
Web API の未来 について考える
https://trends.google.co.jp/trends/explore?date=all&q=Web%20API,REST%20API
Web API の歴史を遡る ※諸説あります Photo by https://flic.kr/p/8iSBWB
REST + JSON • 2010年年頃から現在の主流 • ブラウザとの親和性
REST + XML • 2005年年 Ajax の登場 • 2005年年 REST
ムーブメント • ブラウザの時代へ
XML-RPC • 1999年年頃 仕様策定 • RPC を HTTP の上で⾏行行うプロトコルのひとつ •
Firewall を越えてインターネットワイドに • 2001年年頃 SOAP 誕⽣生
RPC • Remote Procedure Call • ネットワーク越しに関数呼び出しするという意味で は Web API
の原点にある(と思う) • 独⾃自ポートを開けるなど Firewall を越える課題など
RPC XML-RPC REST + XML REST + JSON 2000年年 2005年年
2010年年 2015年年
サーバサイド • 独⾃自サーバから Web サーバへ • インターナルからインターネットへ • 独⾃自フォーマットから JSON
へ
クライアントサイド • 専⽤用プログラムからブラウザへ • C⾔言語などから JavaScript へ • 単純なマークアップ(HTML)から SPA
へ
REST の功罪 Photo by https://flic.kr/p/ogSP8K
REST によって HTTP の表現だけでリソースごとのシ ンプルなアクセスが提供できた⼀一⽅方で、⼤大量量のリソー スを抱えるサービスは多くのエンドポイントを持つた め、複数リソースからデータの取得が必要な場合に複 数回の API コールを余儀なくされる結果、主にクラ
イアントサイドのオーバヘッドが増え、⾮非同期処理理や ローカルキャッシュなどの技術を駆使することによる 実装の複雑化を増幅した結果、サーバサイド以上にク ライアントサイドは⾼高度な技術を要求されることとなっ た。
http://graphql.org/
– GraphQL Tokyo https://www.meetup.com/ja-JP/GraphQL-Tokyo/events/239924595/ “Meetup #1 Thinking in GraphQL”
– POSTD http://postd.cc/api-paradigms/ “GraphQLはWeb APIの次のフロンティアか?”
GraphQL • 2012年年 Facebook 開発 • 2015年年 Working Draft 公開
• http://graphql.org/
• プロトコル • アーキテクチャ • ソフトウェア • クエリー⾔言語 GraphQL
type Talk { title: String event: String speaker: String keywords:
[String] } type Query { talk(title: String): Talk }
type Talk { title: String! event: String! speaker: String! keywords:
[String] } type Root { talk(title: String): Talk } schema { query: Root }
{ talk(title: "Web API の未来") { title event speaker keywords
} }
{ "data": { "talk": { "title": "Web API の未来", "event":
"YAPC::Fukuoka 2017", "speaker": "Takatsugu Shigeta", "keywords": ["API", "GraphQL"] } } }
Request { talk(title: "Foo") { title event speaker keywords }
} Response { "data": { "talk": { "title": "Foo", "event": "YAPC::Fukuo "speaker": "Mike Jone "keywords": ["Alice", } } }
$ curl -s\ > -H 'Content-Type: application/json'\ > -H 'Authorization:
Bearer ...YOUR TOKEN…'\ > -d '{ "query": "{ viewer { login } }" }'\ > https://api.github.com/graphql | jq . { "data": { "viewer": { "login": "comewalk" } } } JSON でリクエスト
struct Talk { char* title; char* event; char* speaker; char*
keywords; }; struct Talk t; talk("Foo", &t); printf("%s", t->title); // "Foo" RPC の時代に似てますね! (20年年以上のあいだ、形を変えてもやっていることは同じ)
操作(Operations) • Query (データ問い合わせ) • Mutation (データ操作) • Subscription (データ更更新通知)
Query (データ問い合わせ) type UserQuery { search(name: String): [User] } schema
{ query: UserQuery } type Query { search(name: String): [User] }
Query (データ問い合わせ) Request query { search(name: "Foo") { name email
} } Response { "data": { [{ "name": "Bob", "email": "
[email protected]
" }] } }
Mutation (データ操作) type UserMutation { update(name: String): Int } schema
{ muration: UserMutation } type Mutation { update(name: String): Int }
Mutation (データ操作) Request mutation { update(name: "Foo") { result }
} Response { "data": { 1 } }
Subscription (データ更更新通知)
–GitHub https://developer.github.com/early-access/graphql/ https://developer.github.com/v4/ “The ability to define and specify precisely
the data you want for your integration is a powerful advantage over the existing REST endpoints. ” 事例例: GitHub
–Facebook https://facebook.github.io/relay/ “A JavaScript framework for building data- driven React
applications” 事例例: Relay
クライアント アプリケーション サーバ • 構⽂文解析 • 結果返却 GraphQL
クライアント アプリケーション サーバ GraphQL Proxy • 構⽂文解析 • データ収集 •
結果返却 GraphQL REST
クライアント アプリケーション サーバ GraphQL Proxy • 構⽂文解析 • データ収集 •
結果返却 GraphQL REST 外部Webサービス DBサーバ
–Netflix http://netflix.github.io/falcor/starter/what-is-falcor.html “Falcor is middleware.〜 Falcor can be used to
optimize communication between the layers of a new or existing application.” Falcor
https://netflix.github.io/falcor/documentation/network-diagram.png
Web API の未来 • Facebook, Netflix, GitHub など⼤大⼿手が動き始めた • GitHub
API は v3 が REST、v4 が GraphQL • REST が GraphQL に置き換わることは当⾯面ないと思う • だけど(ほぼ)5年年周期で変わるトレンドのはじまり • フォーマットは JSON • REST 原理理主義は卒業してもいい • きっと次に⽣生まれる何かが Web API の未来を担う
"phrase": { "text": "One more thing..." }
"CPAN": { "module": { "name": "GraphQL", "author": "SHIGETA" } }
"CPAN": { "module": { "name": "GraphQL", "author": "SHIGETA" => "ETJ"
} }
"CPAN": { "module": { "name": "GraphQL::Tiny", "author": "SHIGETA" } }
#!/usr/bin/perl use common::sense; use GraphQL::Tiny; use JSON; my $result =
GraphQL::Tiny->new( schema => <<'SCHEMA', type Query { hello: String bye: String } SCHEMA source => '{ hello }', root_value => { hello => sub { return 'Fukuoka'; } }, )->run(); say JSON->new->encode($result); $ perl hello.pl { "data": { "hello": "Fukuoka" } }
"links":[{ "rel": "self", "title": "Happy coding!", }, { "rel": "next",
"title": "Any Question?", "href": "@comewalk" }]