SlideShare a Scribd company logo
RESTful Arch
Benjamin Tan
1
about
• Benjamin Tan
• @tanbamboo
• github.com/tanbamboo
2
agenda
• Lesson 1
• what?
• why?
• Lesson 2
• how?
• how? in Java(using JAX-RS)
• Lesson 3
• good practice? bad practice?
• more?
3
what?
• what is REST? what is RESTful arch?
4
what?
• Representational state transfer (REST) is a style
of software architecture for distributed systems
such as the World Wide Web. REST has
emerged as a predominant web API design
model.
• Representational State
Transfer REST Roy Fielding
2000
5
the Author of REST
• Fielding HTTP 1.0
1.1 Apache
Apache
•
• REST
6
REST Triangle
• /nouns
• /verbs
• /content
types
7
/Resources
• REST " " " "
" " Resources " "
• " "
•
• URI
URI
• URI URI
8
• HTTP
• GET
• POST
• PUT
• DELETE
• HEAD OPTIONS CONNECT
TRACE
9
/Representation
• " "
• " " " /
/Representation"
• txt HTML
XML JSON
JPG PNG
• URI
10
key goals
• Scalability of component interactions
• Generality of interfaces
• Independent deployment of components
• Intermediary components to reduce
latency, enforce security and encapsulate
legacy systems
11
Constraints
• Client–server
• Stateless
• Cacheable
• Layered system
• Code on demand (optional)
• Uniform interface
12
• REST REST HTTP
URI XML HTML
• URI
•
HTTP GET POST PUT DELETE
•
• XML HTML
web web
13
REST
• HTTP
•
•
• REST
14
HATEOAS
•
15
REST Data Elements
• Resource - the intended conceptual target of a
hypertext reference
• Resource identifier – URL, URN
• Representation – HTML document, JPEG image
• Representation metadata – media type, last-
modified time
• Resource metadata – source link, alternates, vary
• Control data – if-modified-since, cache-control
16
REST Connectors
• Client - libwww, libwww-perl
• Server - libwww,Apache API, NSAPI
• Cache - browser cache,Akamai cache
network
• Resolver - bind (DNS lookup library)
• Tunnel - SOCKS, SSL after HTTP
CONNECT
17
REST Components
• User Agent – Netscape Navigator, Lynx,
MOMspider
• Origin Server – Apache httpd, Microsoft
IIS
• Gateway - Squid, CGI, Reverse Proxy
• Proxy - CERN Proxy, Netscape Proxy,
Gauntlet
18
why?
19
style design
20
REST
• Cache
•
•
• HTTP REST
•
•
21
network application
style
• / (MQ WebSocket)
• (P2P ZooKeeper)
• /
22
•
• The PUT and DELETE methods are
idempotent methods.
• The GET method is a safe method (or
nullipotent), meaning that calling it
23
Samples broken
Idempotent
• WebScan
• Robot
• http://stackoverflow.com/questions/
10519064/why-is-using-a-http-get-to-
update-state-on-the-server-in-a-restful-
call-incorrec
24
RESTful & Cloud
•
• RESTful API
• AWS API
• Twitter API
• http://www.infoq.com/news/2011/01/rest-
cloud
25
RESTful & SOA
26
RESTful & RIA
•
• RIA+REST
REST
27
RESTful & Mobile
28
Open Question?
• RESTful WAF
?
• RESTful LB ?
• RESTful CDN
?
29
the philosophy of
design
•
30
how?
31
Guiding principles of
the interface
• The uniform interface that any REST interface must provide is considered fundamental to the design of
any REST service.
• Identification of resources
• Individual resources are identified in requests, for example using URIs in web-based REST systems.
The resources themselves are conceptually separate from the representations that are returned
to the client. For example, the server does not send its database, but rather, perhaps, some HTML,
XML or JSON that represents some database records expressed, for instance, in Swahili and
encoded in UTF-8, depending on the details of the request and the server implementation.
• Manipulation of resources through these representations
• When a client holds a representation of a resource, including any metadata attached, it has enough
information to modify or delete the resource on the server, provided it has permission to do so.
• Self-descriptive messages
• Each message includes enough information to describe how to process the message. For example,
which parser to invoke may be specified by an Internet media type (previously known as a MIME
type). Responses also explicitly indicate their cacheability.[1]
• Hypermedia as the engine of application state (aka HATEOAS)
• Clients make state transitions only through actions that are dynamically identified within
hypermedia by the server (e.g., by hyperlinks within hypertext). Except for simple fixed entry
points to the application, a client does not assume that any particular action is available for any
particular resources beyond those described in representations previously received from the
server.
32
RESTful
•
• Resource-based vs.Action-based
•
•
33
HTTP
34
35
Cache
• Proxy
• Expires Cache-Control
• Last-Modified ETag
• 304 (Not Modified)
36
in one stentence
• REST is everywhere. It is the part of the web
that makes it work well. If you want to build
distributed applications that can scale like
the web, be resilient to change like the web
and promote re-use as the web has done,
then follow the same rules they did when
building web browsers.
• http://stackoverflow.com/questions/1368014/
why-do-we-need-restful-web-services
37
Good Practices
• Map your API model to the way your
data is consumed, not your data/object
model.
• Meaningful error messages help a lot.
• Providing solid API documentation
reduces need for external help.
• Use an appropriate security APIs.
38
bad practices
• Chatty APIs suck.
• Returning HTML in response.
• Failing to realize that a 4xx error means I
messed up and a 5xx means you messed
up
• Side-effects to 500 errors are evil.
• http://broadcast.oreilly.com/2011/06/the-
39
how? in Java
(using JAX-RS)
40
JAX-RS
• JSR 311: JAX-RS:The Java API for RESTful Web Services
• Java EE 6 JSR-311 JSR-311
Java
REST
• JSR 339: JAX-RS 2.0
• Java EE 7 with JAX-RS 2.0 brings several useful features,
which further simplify development and lead to the
creation of even more-sophisticated, but lean, Java SE/EE
RESTful applications.
41
JAX-RS API
<dependency>	
				<groupId>javax.ws.rs</groupId>	
				<artifactId>javax.ws.rs-api</artifactId>	
				<version>2.0</version>	
</dependency>	
<dependency>	
				<groupId>javax.ws.rs</groupId>	
				<artifactId>jsr311-api</artifactId>	
				<version>1.1.1</version>	
</dependency>
42
JAX-RS
• @POST @GET @PUT
@DELETE 4 HTTP
• @Path
43
JAX-RS
• JAX-RS Resource
@PathParam @MatrixParam @QueryParam
@FormParam @HeaderParam
@CookieParam @DefaultValue @Encoded
• @PathParam
@Path
44
JAX-RS
• Web
Content Negotiation
• Resource @Produces
MIME @Consumes
• Accept Content-
Type
• JAX-RS MessageBodyReader MessageBodyWriter
XML / Java JAXB
• @Provider MessageBodyProvider
45
JAX-RS
• Jersey
• JBoos Resteasy
• Apache Wink
• Play! Framework
46
JAX-RS
• Spring @MVC
• Restlet
47
how? other languages
• Rails(ruby)
• Sinatra(ruby)
• Tornado Web(python)
• Django REST(python)
• spray(scala)
• More RESTful frameworks:
• https://code.google.com/p/implementing-rest/
wiki/RESTFrameworks
48
more?
49
• HTTP
WebSockets REST
• REST
• SSL/TLS REST WS-Sec*
REST SSL
REST REST
• REST QoS
“ ”
50
API versioning
• API REST
51
POST
• post
•
52
reference 1
1.http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm
2.http://www.redsaga.com/opendoc/REST_cn.pdf
3.https://en.wikipedia.org/wiki/REST
4.https://zh.wikipedia.org/wiki/REST
5.http://www.w3.org/Protocols/rfc2616/rfc2616.html
6.http://www.infoq.com/cn/rest
7.http://www.infoq.com/cn/minibooks/restful-web-services-cookbook-cn
8.https://jax-rs-spec.java.net/
9.http://jcp.org/en/jsr/detail?id=339
10.https://zh.wikipedia.org/wiki/JAX-RS
11.http://www.ibm.com/developerworks/cn/java/j-lo-jaxrs/
12.https://jersey.java.net/
13.http://www.slideshare.net/landlessness/teach-a-dog-to-rest
53
reference 2
1.http://www.jboss.org/resteasy
2.http://blog.springsource.org/2009/03/08/rest-in-spring-3-mvc/
3.http://restlet.org/
4.http://www.infoq.com/cn/news/2008/10/jaxrs-comparison
5.http://www.infoq.com/news/2013/05/rest-drawbacks
6.http://www.infoq.com/cn/news/2013/06/rest-drawbacks
7.http://www.infoq.com/cn/articles/webber-rest-workflow
8.http://restfulobjects.org/
9.http://www.infoq.com/cn/interviews/robinson-webber-rest-cn
10.http://aws.amazon.com/cn/s3/
11.http://tools.ietf.org/html/rfc2046
12.http://www.iana.org/assignments/media-types
13.http://blog.toright.com/archives/725
54

More Related Content

KEY
Seda与Java并行编程点滴
PDF
Cloud Development with Camel and Amazon Web Services
PPTX
Camel Based Development Application
PDF
ActiveMQ Performance Tuning
PPTX
Essential Camel Components
PDF
Camel oneactivemq posta-final
PPT
ActiveMQ 5.9.x new features
PPSX
Restful web services rule financial
Seda与Java并行编程点滴
Cloud Development with Camel and Amazon Web Services
Camel Based Development Application
ActiveMQ Performance Tuning
Essential Camel Components
Camel oneactivemq posta-final
ActiveMQ 5.9.x new features
Restful web services rule financial

What's hot (20)

PDF
Polyglot Messaging with Apache ActiveMQ
PDF
DevOps with ActiveMQ, Camel, Fabric8, and HawtIO
PDF
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
 
PPTX
High Volume Web API Management with WSO2 ESB
PPTX
Expect the unexpected: Anticipate and prepare for failures in microservices b...
PPTX
Melbourne User Group OAK and MongoDB
PDF
Keynote Oracle Fusion Middleware Summit_2020
PPTX
Servletarchitecture,lifecycle,get,post
PPT
File System On Steroids
PPT
Weblogic configuration & administration
PPT
Weblogic - clustering failover, and load balancing
PDF
Oracle Fuson Middleware Diagnostics, Performance and Troubleshoot
PDF
Jakarta EE 8 on JDK17
PPT
Git preso to valtech cfml team
PPTX
Microservices with Apache Camel, Docker and Fabric8 v2
PDF
On being RESTful
PDF
WebLogic on ODA - Oracle Open World 2013
PPTX
WebLogic Administration course outline
PPT
WebLogic Scripting Tool Overview
Polyglot Messaging with Apache ActiveMQ
DevOps with ActiveMQ, Camel, Fabric8, and HawtIO
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
 
High Volume Web API Management with WSO2 ESB
Expect the unexpected: Anticipate and prepare for failures in microservices b...
Melbourne User Group OAK and MongoDB
Keynote Oracle Fusion Middleware Summit_2020
Servletarchitecture,lifecycle,get,post
File System On Steroids
Weblogic configuration & administration
Weblogic - clustering failover, and load balancing
Oracle Fuson Middleware Diagnostics, Performance and Troubleshoot
Jakarta EE 8 on JDK17
Git preso to valtech cfml team
Microservices with Apache Camel, Docker and Fabric8 v2
On being RESTful
WebLogic on ODA - Oracle Open World 2013
WebLogic Administration course outline
WebLogic Scripting Tool Overview
Ad

Viewers also liked (20)

DOC
BE IN ELECTRONICS AND COMMUNICATION WITH 1 YEAR EXPERIENCE
PPTX
MiDulceLocura y EmporioDianora
PPTX
148indianmobileinitiatifinal20110406 110408083717-phpapp02
PPTX
GoToMeetings
PPTX
Агман Забуровна
PPTX
LM_MAHAMMAD_GOUSE_CV_Jul15
PPTX
PPTX
Profitable Sustainability
PPTX
Violin Memory DOAG (German Oracle User Group) Nov 2012
PDF
Pragadees Resume
PDF
Compliance Management Software
PDF
Certificate Of Participation
PDF
The five graphs of telecommunications may 22 2013 webinar final
PDF
One night at the call center by chetan bhagat
PDF
Score your Goals, Leave Password Management to us!
DOC
Pradeep_iOS_Developer
PDF
Test PPT
PPT
Presentation EOI - Apps & Tech 2.0
PPS
Wedding Invite
PPTX
Business process reengineering
BE IN ELECTRONICS AND COMMUNICATION WITH 1 YEAR EXPERIENCE
MiDulceLocura y EmporioDianora
148indianmobileinitiatifinal20110406 110408083717-phpapp02
GoToMeetings
Агман Забуровна
LM_MAHAMMAD_GOUSE_CV_Jul15
Profitable Sustainability
Violin Memory DOAG (German Oracle User Group) Nov 2012
Pragadees Resume
Compliance Management Software
Certificate Of Participation
The five graphs of telecommunications may 22 2013 webinar final
One night at the call center by chetan bhagat
Score your Goals, Leave Password Management to us!
Pradeep_iOS_Developer
Test PPT
Presentation EOI - Apps & Tech 2.0
Wedding Invite
Business process reengineering
Ad

Similar to Restful风格ž„web服务架构 (20)

PPTX
RESTful services
PPTX
RESTful Web Services
PDF
What are restful web services?
PPTX
REST & RESTful APIs: The State of Confusion
PPTX
Mini-Training: Let's have a rest
PPT
emilio.ppt
PPT
emilio.ppt
PPTX
RESTful APIs
PPTX
Overview of REST - Raihan Ullah
PPTX
A Deep Dive into RESTful API Design Part 1
PDF
PPTX
REST Presentation
PDF
RESTful applications: The why and how by Maikel Mardjan
PPTX
JAX-RS. Developing RESTful APIs with Java
PDF
What is REST?
PPTX
REST and RESTful Services
PPTX
Restful webservice
PPTX
RESTful Services
PPTX
Introduction to Web Services
PPTX
Rest APIs Training
RESTful services
RESTful Web Services
What are restful web services?
REST & RESTful APIs: The State of Confusion
Mini-Training: Let's have a rest
emilio.ppt
emilio.ppt
RESTful APIs
Overview of REST - Raihan Ullah
A Deep Dive into RESTful API Design Part 1
REST Presentation
RESTful applications: The why and how by Maikel Mardjan
JAX-RS. Developing RESTful APIs with Java
What is REST?
REST and RESTful Services
Restful webservice
RESTful Services
Introduction to Web Services
Rest APIs Training

Recently uploaded (20)

PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
A Presentation on Artificial Intelligence
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation theory and applications.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Chapter 3 Spatial Domain Image Processing.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
A Presentation on Artificial Intelligence
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation theory and applications.pdf
Machine learning based COVID-19 study performance prediction
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Unlocking AI with Model Context Protocol (MCP)
The Rise and Fall of 3GPP – Time for a Sabbatical?
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Per capita expenditure prediction using model stacking based on satellite ima...
NewMind AI Weekly Chronicles - August'25 Week I
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Review of recent advances in non-invasive hemoglobin estimation
Advanced methodologies resolving dimensionality complications for autism neur...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Digital-Transformation-Roadmap-for-Companies.pptx
Approach and Philosophy of On baking technology
Encapsulation_ Review paper, used for researhc scholars
Chapter 3 Spatial Domain Image Processing.pdf

Restful风格ž„web服务架构