SlideShare a Scribd company logo
‘RESTFUL 2.0’
Is Here and Its Name Is
GraphQL
Who’s Using GraphQL
Introduction to RESTFUL
• GET /posts - Retrieves a list of posts

• GET /posts/12 - Retrieves a specific post

• POST /posts - Creates a new post

• PUT /posts/12 - Updates post #12

• PATCH /posts/12 - Partially updates post
#12

• DELETE /posts/12 - Deletes post #12
• http response 会附带着合适的HTTP Status
Code,可以清楚知道这次请求的结果

• 例例如: 

• 200 OK

• 400 Bad Request

• 403 Forbidden

• 404 Not Found
3
Hacker News example
Data Model
GET /posts
、
{
posts: [
{
id: 1,
author_id: 101,
title: 'GraphQL in an Age of REST',
body: 'lorem ipsum',
votes: 342,
published_at: '2016-10-11T16:53:28+00:00'
}
]
}
Problem 1: Multiple
roundtrips
GET /posts
、
{
posts: [
{
id: 1,
author_id: 101,
title: 'GraphQL in an Age of REST',
body: 'lorem ipsum',
votes: 342,
published_at: '2016-10-11T16:53:28+00:00'
}
]
}
GET /users/101
{
user: {
id: 101,
name: 'yosriady',
joined_at: '2015-10-11T16:53:28+00:00'
}
}
GET /users/103
GET /users/104
GET /users/105
。。。
处理理资源之间的关联就变成⼀一个灰⾊色地带
Rest 2.0 graph ql
Solution: Autoload related
resources
• GET /posts/1?embed=author.name

{
post: {
id: 1,
author_id: 101,
title: 'GraphQL in an Age of REST',
body: 'lorem ipsum',
votes: 342,
published_at: '2016-10-11T16:53:28+00:00',
author: {
name: 'yosriady'
}
}
}
Problem 2: Over-fetching of
data
• APIs often return a huge JSON object with many fields,
even when we only use a handful.

• Solution: Clients should be able to specify the fields they
only need

• GET /posts/1?fields=title,link,published_at
Problem 3: How will users
learn our API?
• 调试接⼝口—麻烦

• Documentation
Why GraphQL ?
• 多次请求获得数据 Multiple roundtrips

• Facebook内部,⼤大量量不不同的app和系统共同使⽤用着许许多多
的服务api,随着业务的变化和发展,不不同app对相同资源的
不不同使⽤用⽅方法最终导致需要维护的服务api数量量爆炸式的增
⻓长。

• 创建⼀一个⼤大⽽而全的通⽤用性接⼝口⼜又⾮非常不不利利于移动端使⽤用(流
量量损耗),⽽而且后端数据的⽆无意义聚合也对整个系统带来了了
很⼤大的资源浪费。

• 接⼝口需要完整API 

• 在这样的背景下,fb⼯工程师坐不不住了了,于是乎GraphQL的概
念就诞⽣生了了~最了了解客户端需要什什么数据的只有客户端⾃自⼰己,
所以如果给客户端提供⼀一种机制,让其表述⾃自⼰己所需的数据
结构,这岂不不是最合理理的么
● A
什什么是 GraphQL
• A GraphQL query is a string interpreted by a server that
returns data in a specified format.

• 什什么⻤鬼??

• (1) Query language

• (2) Type system 

• (3) Runtime for client applications to fetch and mutate
data.
“Talk is cheap. Show
me the code.”
Hello GraphQL
代码实现Hello GraphQL
(Node JS)
Nested Data
代码实现Nested Data
(Node JS)
Mutation
官⽹网
• http://graphql.org/learn/

More Related Content

PDF
Infinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic
PPTX
Ztech Connect '19, IBM PureApplication
PDF
A quick introduction to Storm Crawler
PDF
Retro vs volley (2)
PPTX
Caching and invalidating with managed store
PDF
Your rest api using laravel
PPTX
Building a scalable online backup system in python
PDF
Install Oracle 12c Golden Gate On Oracle Linux
Infinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic
Ztech Connect '19, IBM PureApplication
A quick introduction to Storm Crawler
Retro vs volley (2)
Caching and invalidating with managed store
Your rest api using laravel
Building a scalable online backup system in python
Install Oracle 12c Golden Gate On Oracle Linux

What's hot (20)

PPT
Solbase & Real-time Activity
PPTX
Groovy example in mule
PPT
Learn REST API with Python
PDF
Multi-threaded web crawler in Ruby
PDF
Configure Golden Gate Initial Load and Change Sync
KEY
Hibernate Performance Tuning (JEEConf 2012)
PDF
Oracle 11g to 12c Upgrade With Data Guard and ASM
PPT
Integrated version control with Fossil SCM
PDF
XtraDB 5.6 and 5.7: Key Performance Algorithms
PPTX
Practical Replication June-2011
PDF
Beating Python's GIL to Max Out Your CPUs
PPTX
2. http, html
PDF
HTTP2 in action - Piet Van Dongen - Codemotion Amsterdam 2017
PDF
RESTful Web Services in Drupal7
PPTX
Apache Solr for begginers
PDF
Profiling TYPO3 Flow Applications
PDF
Network Device Database Management with REST using Jersey
PPTX
Automated testing web services - part 1
PDF
Fossil scm overview
DOCX
C# and Borland StarTeam Connectivity
Solbase & Real-time Activity
Groovy example in mule
Learn REST API with Python
Multi-threaded web crawler in Ruby
Configure Golden Gate Initial Load and Change Sync
Hibernate Performance Tuning (JEEConf 2012)
Oracle 11g to 12c Upgrade With Data Guard and ASM
Integrated version control with Fossil SCM
XtraDB 5.6 and 5.7: Key Performance Algorithms
Practical Replication June-2011
Beating Python's GIL to Max Out Your CPUs
2. http, html
HTTP2 in action - Piet Van Dongen - Codemotion Amsterdam 2017
RESTful Web Services in Drupal7
Apache Solr for begginers
Profiling TYPO3 Flow Applications
Network Device Database Management with REST using Jersey
Automated testing web services - part 1
Fossil scm overview
C# and Borland StarTeam Connectivity
Ad

Similar to Rest 2.0 graph ql (20)

PDF
Spring MVC to iOS and the REST
PPTX
Spring Boot and REST API
PDF
Week 09 -Servlets-part1.pdf
PDF
HTTP / 1, HTTP / 2 and HTTP / 3: Past, present and the future of APIs
PPTX
Unit III Servlets in Java by Sun micro.pptx
PDF
Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...
PDF
03 form-data
PPTX
Boost Your Content Strategy for REST APIs with Gururaj BS
PDF
PDF
Web services tutorial
PDF
Web Services Tutorial
PPTX
SCWCD : The servlet model CHAP : 2
PPTX
Performance #4 network
PPTX
Spring MVC 3 Restful
PDF
GraphConnect 2014 SF: From Zero to Graph in 120: Scale
PPTX
SCWCD : The servlet model : CHAP : 2
PPTX
REST with Eve and Python
PDF
[OpenTRS-001] ooops
PDF
Bootstrapping multidc observability stack
PDF
Sun certifiedwebcomponentdeveloperstudyguide
Spring MVC to iOS and the REST
Spring Boot and REST API
Week 09 -Servlets-part1.pdf
HTTP / 1, HTTP / 2 and HTTP / 3: Past, present and the future of APIs
Unit III Servlets in Java by Sun micro.pptx
Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...
03 form-data
Boost Your Content Strategy for REST APIs with Gururaj BS
Web services tutorial
Web Services Tutorial
SCWCD : The servlet model CHAP : 2
Performance #4 network
Spring MVC 3 Restful
GraphConnect 2014 SF: From Zero to Graph in 120: Scale
SCWCD : The servlet model : CHAP : 2
REST with Eve and Python
[OpenTRS-001] ooops
Bootstrapping multidc observability stack
Sun certifiedwebcomponentdeveloperstudyguide
Ad

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Approach and Philosophy of On baking technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation theory and applications.pdf
PDF
KodekX | Application Modernization Development
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
Teaching material agriculture food technology
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Review of recent advances in non-invasive hemoglobin estimation
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Empathic Computing: Creating Shared Understanding
Approach and Philosophy of On baking technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation theory and applications.pdf
KodekX | Application Modernization Development
Unlocking AI with Model Context Protocol (MCP)
Dropbox Q2 2025 Financial Results & Investor Presentation
“AI and Expert System Decision Support & Business Intelligence Systems”
Mobile App Security Testing_ A Comprehensive Guide.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Teaching material agriculture food technology
Electronic commerce courselecture one. Pdf
Encapsulation_ Review paper, used for researhc scholars
sap open course for s4hana steps from ECC to s4
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
20250228 LYD VKU AI Blended-Learning.pptx

Rest 2.0 graph ql

  • 1. ‘RESTFUL 2.0’ Is Here and Its Name Is GraphQL
  • 3. Introduction to RESTFUL • GET /posts - Retrieves a list of posts • GET /posts/12 - Retrieves a specific post • POST /posts - Creates a new post • PUT /posts/12 - Updates post #12 • PATCH /posts/12 - Partially updates post #12 • DELETE /posts/12 - Deletes post #12 • http response 会附带着合适的HTTP Status Code,可以清楚知道这次请求的结果 • 例例如: • 200 OK • 400 Bad Request • 403 Forbidden • 404 Not Found 3
  • 6. GET /posts 、 { posts: [ { id: 1, author_id: 101, title: 'GraphQL in an Age of REST', body: 'lorem ipsum', votes: 342, published_at: '2016-10-11T16:53:28+00:00' } ] }
  • 7. Problem 1: Multiple roundtrips GET /posts 、 { posts: [ { id: 1, author_id: 101, title: 'GraphQL in an Age of REST', body: 'lorem ipsum', votes: 342, published_at: '2016-10-11T16:53:28+00:00' } ] } GET /users/101 { user: { id: 101, name: 'yosriady', joined_at: '2015-10-11T16:53:28+00:00' } } GET /users/103 GET /users/104 GET /users/105 。。。 处理理资源之间的关联就变成⼀一个灰⾊色地带
  • 9. Solution: Autoload related resources • GET /posts/1?embed=author.name { post: { id: 1, author_id: 101, title: 'GraphQL in an Age of REST', body: 'lorem ipsum', votes: 342, published_at: '2016-10-11T16:53:28+00:00', author: { name: 'yosriady' } } }
  • 10. Problem 2: Over-fetching of data • APIs often return a huge JSON object with many fields, even when we only use a handful. • Solution: Clients should be able to specify the fields they only need • GET /posts/1?fields=title,link,published_at
  • 11. Problem 3: How will users learn our API? • 调试接⼝口—麻烦 • Documentation
  • 12. Why GraphQL ? • 多次请求获得数据 Multiple roundtrips • Facebook内部,⼤大量量不不同的app和系统共同使⽤用着许许多多 的服务api,随着业务的变化和发展,不不同app对相同资源的 不不同使⽤用⽅方法最终导致需要维护的服务api数量量爆炸式的增 ⻓长。 • 创建⼀一个⼤大⽽而全的通⽤用性接⼝口⼜又⾮非常不不利利于移动端使⽤用(流 量量损耗),⽽而且后端数据的⽆无意义聚合也对整个系统带来了了 很⼤大的资源浪费。 • 接⼝口需要完整API • 在这样的背景下,fb⼯工程师坐不不住了了,于是乎GraphQL的概 念就诞⽣生了了~最了了解客户端需要什什么数据的只有客户端⾃自⼰己, 所以如果给客户端提供⼀一种机制,让其表述⾃自⼰己所需的数据 结构,这岂不不是最合理理的么 ● A
  • 13. 什什么是 GraphQL • A GraphQL query is a string interpreted by a server that returns data in a specified format. • 什什么⻤鬼?? • (1) Query language • (2) Type system • (3) Runtime for client applications to fetch and mutate data.
  • 14. “Talk is cheap. Show me the code.”