techniques for composing rest services - jopera
TRANSCRIPT
Techniques for Composing REST services
Cesare PautassoFaculty of Informatics
University of Lugano, Switzerland
[email protected]://www.pautasso.info
©2009 - Cesare Pautasso 2
Abstract Novel trends in Web services technology challenge
the assumptions made by current standards for process-based service composition. For example, most existing RESTful Web service APIs (which do not rely on the Web Service Description Language), cannot natively be composed using the WS-BPEL language.
In this talk we introduce the problem of composing RESTful services and compare it to Web 2.0 service mashups. We cover several real-world examples demonstrating how existing composition languages can be evolved to cope with REST. We conclude by showing that the uniform interface and hyper-linking capabilities of RESTful services provides an excellent abstraction for exposing in a controlled way the state of business process as a resource.
©2009 - Cesare Pautasso 3
About Cesare Pautasso Assistant Professor at the Faculty of Informatics,
University of Lugano, Switzerland (since Sept 2007)Research Projects: SOSOA – Self- Organizing Service Oriented Architectures CLAVOS – Continuous Lifelong Analysis and Verification of
Open Services BPEL for REST
Researcher at IBM Zurich Research Lab (2007) Post- Doc at ETH Zürich Software:
JOpera: Process Support for more than Web serviceshttp://www.jopera.org/
Ph.D. at ETH Zürich, Switzerland (2004)
Representations: http://www.pautasso.info/ (Web) http://twitter.com/pautasso/ (Twitter Feed)
©2009 - Cesare Pautasso 4
Why Composition?
Composition is the key SOA principle with the goal of enabling
service reuse
©2009 - Cesare Pautasso 5
Uniform Interface (Reuse Contract) Status Codes (Reuse Metadata) Representations (Reuse Media Types) Middleware (Reuse caching, security,
load balancing, proxies components)
REST and Reuse
©2009 - Cesare Pautasso 6
Web Services expose their data and functionality trough resources identified by URI
Uniform Interface Principle: Clients interact with resources through a fix set of verbs. Example HTTP:GET (read), POST (create), PUT (update), DELETE
Multiple representations for the same resource Hyperlinks model resource relationships and valid
state transitions for dynamic protocol description and discovery
REST in one slide
RPUT
DELETE
GET
POST
©2009 - Cesare Pautasso 7
Uniform Interface (Reuse Contract) Status Codes (Reuse Metadata) Representations (Reuse Media Types) Middleware (Reuse caching, security,
load balancing, proxies components)
Yes, but what about reusing entire RESTfulservices?
REST and Reuse
©2009 - Cesare Pautasso 8
1. Defining RESTful service composition
2. Example: DoodleMap
3. What about mashups?
4. BPM and REST
RESTful Composition Techniques
©2009 - Cesare Pautasso 9
REST Architectural Elements
User Agent Origin Server
Cache
Proxy
Gateway
Connector (HTTP)
Client/Server Layered CacheStateless Communication
©2009 - Cesare Pautasso 10
Basic Setup
User Agent Origin Server
HTTP
CachingUser Agent
Origin Server
HTTP
User Agent CachingOrigin Server
HTTP
Adding Caching
CachingUser Agent
CachingOrigin Server
HTTP
©2009 - Cesare Pautasso 11
Proxy or Gateway?
Client ProxyHTTP Origin Server
HTTP
Client GatewayHTTP
Origin ServerHTTP
Intermediaries forward (and may translate) requests and responses
A proxy is chosen by the Client (for caching, or access control)
The use of a gateway (or reverse proxy) is imposed by the server
©2009 - Cesare Pautasso 12
REST Middleware for Scalability
Origin Server
Clients
Proxy/Gateway
One example of REST middleware is to help with the scalability of a server, which may need to service a very large number of clients
Cache
©2009 - Cesare Pautasso 13
REST Middleware for Composition
Origin Server
Clients
Proxy/Gateway
Composition shifts the attention to the client which should consume and aggregate from many servers
©2009 - Cesare Pautasso 14
Servers
REST Middleware for Composition
Origin Client
The “proxy” intermediate element which aggregates the resources provided by multiple servers plays the role of the composition controller of a composite RESTful service
CompositeRESTfulservice
©2009 - Cesare Pautasso 15
Composite Resources
PUT
DELETE
GET
POST
PUT
DELETE
GET
POST
C
RPUT
DELETE
GET
POST
S
©2009 - Cesare Pautasso 16
Composite Resources
StateR
StateS
C
R S
The composite resource only aggregates the state of its component resources
©2009 - Cesare Pautasso 17
Composite Resources
StateR
StateS
StateC
C
R S
The composite resource augments (or caches) the state of its component resources
©2009 - Cesare Pautasso 18
Web Services expose their data and functionality trough resources identified by URI
Uniform Interface Principle: Clients interact with resources through a fix set of verbs. Example HTTP:GET (read), POST (create), PUT (update), DELETE
Multiple representations for the same resource Hyperlinks model resource relationships and valid
state transitions for dynamic protocol description and discovery
Enter HATEOAS
RPUT
DELETE
GET
POST
©2009 - Cesare Pautasso 19
Composite Representations
PUT
PUT
DELETE
DELETE
GET
GETPOST
POSTC
RS
LinkR
LinkS
Composite Representation
©2009 - Cesare Pautasso 20
Composite Representation Pattern
CompositeRepresentation
Origin Servers
Client
OriginServer
A composite representation is interpreted by the client that follows its hyperlinks and aggregates the state of the referenced component resources
©2009 - Cesare Pautasso 21
Bringing it all together
CompositeRepresentation
Origin Servers
Client
CompositeRESTfulservice
A composite representation can be produced by a composite service too
Origin Servers
©2009 - Cesare Pautasso 22
Doodle Map Example
CompositeRepresentation
Origin Servers
Client
CompositeRESTfulservice
Vote on a meeting place based on its geographic location
Origin Servers
©2009 - Cesare Pautasso 23
1. Composite Resource
PUT
DELETE
GET
POST
PUT
DELETE
GET
POST
C
RPUT
DELETE
GET
POST
S
©2009 - Cesare Pautasso 24
1. Composite Resource
GET
DELETE
GET
POST
C
RPUT
DELETE
GET
POST
S
©2009 - Cesare Pautasso 25
2. Composite Representation
GET
DELETE
GET
POST
C
RPUT
DELETE
GET
POST
S
DMLinkG
LinkC
GETG
LinkD
©2009 - Cesare Pautasso 26
Demo
©2009 - Cesare Pautasso 27
Was it just a Mashup?
MashupREST
Composition
Mashup
(It depends on the definition of Mashup)
©2009 - Cesare Pautasso 28
Read-only vs. Read/Write
Moving state around
PUT
DELETE
GET
POST
PUT
DELETE
GET
POST
C
RPUT
DELETE
GET
POST
S
©2009 - Cesare Pautasso 29
Read-only vs. Read/write
Simply aggregating data (feeds)
GET
GETC
RGET
S
©2009 - Cesare Pautasso 30
UI vs. API Composition
Is your composition reusable?
CompositeRepresentation
Origin Servers
Client
CompositeRESTfulservice
Origin Servers
API
UI Reusable services vs. Reusable Widgets
©2009 - Cesare Pautasso 31
Can you always do thisfrom a web browser?
Single-Origin Sandbox
Client
CompositeRESTfulservice
Origin Servers
Origin Servers
CompositeRepresentation
©2009 - Cesare Pautasso 32
Security Policies on the client may not always allow it to aggregate data from multiple different sources
Single-Origin Sandbox
CompositeRepresentation
Client
CompositeRESTfulservice
N Origin Servers
1 Origin Server
©2009 - Cesare Pautasso 33
Complementary
Mashup RESTComposition
Mashup
Read-OnlyRead/Write
APIUI
SituationalReusable
ServiceSandboxed
©2009 - Cesare Pautasso 34
1. Defining RESTful service composition
2. Example: DoodleMap
3. What about mashups?
4. BPM and REST
RESTful Composition Techniques
©2009 - Cesare Pautasso 35
The WS-BPEL process model is layered on top of the service model defined by WSDL 1.1. […] Both the process and its partners are exposed as WSDL services
[BPEL 2.0 Standard, Section 3]
Web Service Composition Today
WSDL 1.1
WS-BPEL 2.0
©2009 - Cesare Pautasso 36
RESTful Web Services APIs…
WSDL 1.1
…do not use WSDL 1.1
©2009 - Cesare Pautasso 37
WSDL 2.0 HTTP Binding can wrap RESTful Web Services
BPEL/WSDL 2.0
R
WSDL 2.0BPEL PUT
DELETE
GET
POST
Operations
HTTP Binding
Op_1Op_2Op_3Op_4
...
<Invoke Op_1>
<Invoke Op_2>
...
<Invoke Op_3>
<Invoke Op_4>
...
Op_1 R PUTOp_2 R GETOp_3 R POSTOp_4 R DELETE
Op URI Method
R PUTR GETR POSTR DELETE
(WS-BPEL 2.0 does not support WSDL 2.0)
©2009 - Cesare Pautasso 38
BPMWorkflow
Languages
RESTfulWeb ServiceComposition
©2009 - Cesare Pautasso 39
1. Abstract Workflow Service invocation technology does not matter
2. Concrete Workflow Expose service invocation
technologies as explicit constructsin the workflow language
3. RESTful Workflow Workflow as one kind of resource
exposed by a RESTful service
Solutions
BPMWorkflow
Languages
RESTfulWeb ServiceComposition
BPMWorkflow
Languages
RESTfulWeb ServiceComposition
BPMWorkflow
Languages
RESTfulWeb ServiceComposition
©2009 - Cesare Pautasso 40
WSDL 2.0 HTTP Binding can wrap RESTful Web Services
BPEL/WSDL 2.0
R
WSDL 2.0BPEL PUT
DELETE
GET
POST
Operations
HTTP Binding
Op_1Op_2Op_3Op_4
...
<Invoke Op_1>
<Invoke Op_2>
...
<Invoke Op_3>
<Invoke Op_4>
...
Op_1 R PUTOp_2 R GETOp_3 R POSTOp_4 R DELETE
Op URI Method
R PUTR GETR POSTR DELETE
(WS-BPEL 2.0 does not support WSDL 2.0)
©2009 - Cesare Pautasso 41
Make REST interaction primitives first-class language constructs
BPEL for REST
R
BPEL for REST PUT
DELETE
GET
POST
...
<Put R>
<Get R>
...
<Post R>
<Delete R>
...
<Put R>
<Get R>
<Post R>
<Delete R>
©2009 - Cesare Pautasso 42
Dynamically publish resources from BPEL processes and handle client requests
BPEL for REST<Resource P>
<onGet>
<Put R>
<Get S>
</onGet>
<Post R>
<Delete S>
</onDelete>
</Resource>
<onDelete>
R
PUT
DELETE
GET
POST
S
PUT
DELETE
GET
POST
P
PUT
DELETE
GET
POST
BPEL for REST
©2009 - Cesare Pautasso 43
RESTful Workflows
P
R
PUT
DELETE
GET
POST
R
PUT
DELETE
GET
POST
Use the resource interface abstraction to publish the state of the workflow
©2009 - Cesare Pautasso 44
DoodleMap as RESTful workflow
©2009 - Cesare Pautasso 45
Applying the SOA composition principle to REST gives interesting results Thanks to hyperlinks, REST brings a new
(more dynamic and loosely coupled) twist to SOA composition Composing RESTful services helps to build
mashups, but is different A RESTful API is the perfect abstraction for
publishing the state of a workflow
Conclusion
© 46
R. Fielding, Architectural Styles and the Design of Network-based Software Architectures, PhD Thesis, University of California, Irvine, 2000
C. Pautasso, O. Zimmermann, F. Leymann, RESTful Web Services vs. Big Web Services: Making the Right Architectural Decision, Proc. of the 17th International World Wide Web Conference (WWW2008), Bejing, China, April 2008
C. Pautasso, BPEL for REST, Proc. of the 7th International Conference on Business Process Management (BPM 2008), Milano, Italy, September 2008
C. Pautasso, Composing RESTful Services with JOpera,In: Proc. of the International Conference on Software Composition (SC2009), July 2009, Zurich, Switzerland.
References
©2009 - Cesare Pautasso 47
Raj Balasubramanian, Benjamin Carlyle, Thomas Erl, Cesare Pautasso, SOA with REST, Prentice Hall, to appear in 2010