Techniques for Composing REST services Cesare Pautasso Faculty of Informatics University of Lugano, Switzerland c.pautasso@ieee.org http://www.pautasso.info
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 hyperlinking 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 2
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 services http://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 3
Why Composition? Composition is the key SOA principle with the goal of enabling service reuse 2009 - Cesare Pautasso 4
REST and Reuse Uniform Interface (Reuse Contract) Status Codes (Reuse Metadata) Representations (Reuse Media Types) Middleware (Reuse caching, security, load balancing, proxies components) 2009 - Cesare Pautasso 5
REST in one slide Web Services expose their data and functionality trough PUT resources identified by URI R Uniform Interface Principle: Clients interact with resources through a fix set of verbs. Example HTTP: (read), (create), PUT (update), Multiple representations for the same resource Hyperlinks model resource relationships and valid state transitions for dynamic protocol description and discovery 2009 - Cesare Pautasso 6
REST and Reuse 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 RESTful services? 2009 - Cesare Pautasso 7
RESTful Composition Techniques 1. Defining RESTful service composition 2. Example: DoodleMap 3. What about mashups? 4. BPM and REST 2009 - Cesare Pautasso 8
REST Architectural Elements Client/Server Layered Stateless Communication Cache Proxy User Agent Origin Server Gateway Connector (HTTP) Cache 2009 - Cesare Pautasso 9
Basic Setup HTTP User Agent Origin Server Adding Caching HTTP HTTP Caching User Agent Origin Server HTTP User Agent Caching Origin Server Caching User Agent Caching Origin Server 2009 - Cesare Pautasso 10
Proxy or Gateway? Intermediaries forward (and may translate) requests and responses HTTP HTTP Client Proxy Origin Server A proxy is chosen by the Client (for caching, or access control) HTTP HTTP Client Gateway Origin Server The use of a gateway (or reverse proxy) is imposed by the server 2009 - Cesare Pautasso 11
REST Middleware for Scalability Cache Clients Proxy/Gateway Origin Server 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 2009 - Cesare Pautasso 12
REST Middleware for Composition Clients Proxy/Gateway Origin Server Composition shifts the attention to the client which should consume and aggregate from many servers 2009 - Cesare Pautasso 13
REST Middleware for Composition Client Composite RESTful service Origin Servers The proxy intermediate element which aggregates the resources provided by multiple servers plays the role of the composition controller of a composite RESTful service 2009 - Cesare Pautasso 14
Composite Resources PUT C PUT PUT R S 2009 - Cesare Pautasso 15
Composite Resources The composite resource only aggregates the state of its component resources C R S State R State S 2009 - Cesare Pautasso 16
Composite Resources The composite resource augments (or caches) the state of its component resources C State C R S State R State S 2009 - Cesare Pautasso 17
Enter HATEOAS Web Services expose their data and functionality trough PUT resources identified by URI R Uniform Interface Principle: Clients interact with resources through a fix set of verbs. Example HTTP: (read), (create), PUT (update), Multiple representations for the same resource Hyperlinks model resource relationships and valid state transitions for dynamic protocol description and discovery 2009 - Cesare Pautasso 18
Composite Representations Composite Representation C Link R PUT R PUT S Link S 2009 - Cesare Pautasso 19
Composite Representation Pattern Composite Representation Origin Server Client Origin Servers A composite representation is interpreted by the client that follows its hyperlinks and aggregates the state of the referenced component resources 2009 - Cesare Pautasso 20
Bringing it all together Composite Representation Composite RESTful service Origin Servers Client Origin Servers A composite representation can be produced by a composite service too 2009 - Cesare Pautasso 21
Doodle Map Example Composite Representation Composite RESTful service Origin Servers Client Origin Servers Vote on a meeting place based on its geographic location 2009 - Cesare Pautasso 22
1. Composite Resource PUT C PUT PUT R S 2009 - Cesare Pautasso 23
1. Composite Resource C PUT R S 2009 - Cesare Pautasso 24
2. Composite Representation DM G Link G Link C C PUT Link D R S 2009 - Cesare Pautasso 25
Demo 2009 - Cesare Pautasso 26
Was it just a Mashup? Mashup REST Composition (It depends on the definition of Mashup) 2009 - Cesare Pautasso 27
Moving state around Read-only vs. Read/Write PUT C PUT PUT R S 2009 - Cesare Pautasso 28
Simply aggregating data (feeds) Read-only vs. Read/write C R S 2009 - Cesare Pautasso 29
Is your composition reusable? UI vs. API Composition Client Composite Representation UI Origin Servers Composite RESTful service API Origin Servers Reusable services vs. Reusable Widgets 2009 - Cesare Pautasso 30
Single-Origin Sandbox Can you always do this from a web browser? Composite Representation Composite RESTful service Origin Servers Client Origin Servers 2009 - Cesare Pautasso 31
Single-Origin Sandbox Security Policies on the client may not always allow it to aggregate data from multiple different sources Composite Representation Composite RESTful service N Origin Servers Client 1 Origin Server 2009 - Cesare Pautasso 32
Complementary Read-Only Read/Write UI Mashup REST API Composition Situational Sandboxed Reusable Service 2009 - Cesare Pautasso 33
RESTful Composition Techniques 1. Defining RESTful service composition 2. Example: DoodleMap 3. What about mashups? 4. BPM and REST 2009 - Cesare Pautasso 34
Web Service Composition Today 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 WS-BPEL 2.0 WSDL 1.1 [BPEL 2.0 Standard, Section 3] 2009 - Cesare Pautasso 35
RESTful Web Services APIs WSDL 1.1 do not use WSDL 1.1 2009 - Cesare Pautasso 36
BPEL/WSDL 2.0 WSDL 2.0 HTTP Binding can wrap RESTful Web Services (WS-BPEL 2.0 does not support WSDL 2.0) BPEL... <Invoke Op_1> <Invoke Op_2> WSDL 2.0 Operations Op_1 Op_2 Op_3 Op_4 PUT R... <Invoke Op_3> <Invoke Op_4>... HTTP Binding Op URI Method Op_1 R PUT Op_2 R Op_3 R Op_4 R 2009 - Cesare Pautasso 37
BPM Workflow Languages RESTful Web Service Composition 2009 - Cesare Pautasso 38
Solutions 1. Abstract Workflow Service invocation technology does not matter 2. Concrete Workflow Expose service invocation technologies as explicit constructs in the workflow language 3. RESTful Workflow Workflow as one kind of resource exposed by a RESTful service BPM Workflow Languages RESTful Web Service Composition BPM RESTful Workflow Web Service LanguagesComposition BPM RESTful Workflow Web Service Languages Composition 2009 - Cesare Pautasso 39
BPEL/WSDL 2.0 WSDL 2.0 HTTP Binding can wrap RESTful Web Services (WS-BPEL 2.0 does not support WSDL 2.0) BPEL... <Invoke Op_1> <Invoke Op_2> WSDL 2.0 Operations Op_1 Op_2 Op_3 Op_4 PUT R... <Invoke Op_3> <Invoke Op_4>... HTTP Binding Op URI Method Op_1 R PUT Op_2 R Op_3 R Op_4 R 2009 - Cesare Pautasso 40
BPEL for REST Make REST interaction primitives first-class language constructs BPEL for REST... <Put R> <Get R>... <Post R> <Delete R>... PUT R 2009 - Cesare Pautasso 41
BPEL for REST Dynamically publish resources from BPEL processes and handle client requests PUT P BPEL for REST PUT <Resource P> <onget> <Put R> <Get S> </onget> <ondelete> <Post R> <Delete S> </ondelete> </Resource> 2009 - Cesare Pautasso 42 R PUT S
RESTful Workflows PUT P R Use the resource interface abstraction to publish the state of the workflow 2009 - Cesare Pautasso 43
DoodleMap as RESTful workflow 2009 - Cesare Pautasso 44
Conclusion 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 2009 - Cesare Pautasso 45
References R. Fielding, Architectural Styles and the Design of Networkbased 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 7 th 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. 46
Raj Balasubramanian, Benjamin Carlyle, Thomas Erl, Cesare Pautasso, SOA with REST, Prentice Hall, to appear in 2010 2009 - Cesare Pautasso 47