Techniques for Composing REST services - JOpera

47
Techniques for Composing REST services Cesare Pautasso Faculty of Informatics University of Lugano, Switzerland [email protected] http://www.pautasso.info

Transcript of Techniques for Composing REST services - JOpera

Page 1: Techniques for Composing REST services - JOpera

Techniques for Composing REST services

Cesare PautassoFaculty of Informatics

University of Lugano, Switzerland

[email protected]://www.pautasso.info

Page 2: Techniques for Composing REST services - JOpera

©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.

Page 3: Techniques for Composing REST services - JOpera

©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)

Page 4: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 4

Why Composition?

Composition is the key SOA principle with the goal of enabling

service reuse

Page 5: Techniques for Composing REST services - JOpera

©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

Page 6: Techniques for Composing REST services - JOpera

©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

Page 7: Techniques for Composing REST services - JOpera

©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

Page 8: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 8

1. Defining RESTful service composition

2. Example: DoodleMap

3. What about mashups?

4. BPM and REST

RESTful Composition Techniques

Page 9: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 9

REST Architectural Elements

User Agent Origin Server

Cache

Proxy

Gateway

Connector (HTTP)

Client/Server Layered CacheStateless Communication

Page 10: Techniques for Composing REST services - JOpera

©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

Page 11: Techniques for Composing REST services - JOpera

©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

Page 12: Techniques for Composing REST services - JOpera

©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

Page 13: Techniques for Composing REST services - JOpera

©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

Page 14: Techniques for Composing REST services - JOpera

©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

Page 15: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 15

Composite Resources

PUT

DELETE

GET

POST

PUT

DELETE

GET

POST

C

RPUT

DELETE

GET

POST

S

Page 16: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 16

Composite Resources

StateR

StateS

C

R S

The composite resource only aggregates the state of its component resources

Page 17: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 17

Composite Resources

StateR

StateS

StateC

C

R S

The composite resource augments (or caches) the state of its component resources

Page 18: Techniques for Composing REST services - JOpera

©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

Page 19: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 19

Composite Representations

PUT

PUT

DELETE

DELETE

GET

GETPOST

POSTC

RS

LinkR

LinkS

Composite Representation

Page 20: Techniques for Composing REST services - JOpera

©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

Page 21: Techniques for Composing REST services - JOpera

©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

Page 22: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 22

Doodle Map Example

CompositeRepresentation

Origin Servers

Client

CompositeRESTfulservice

Vote on a meeting place based on its geographic location

Origin Servers

Page 23: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 23

1. Composite Resource

PUT

DELETE

GET

POST

PUT

DELETE

GET

POST

C

RPUT

DELETE

GET

POST

S

Page 24: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 24

1. Composite Resource

GET

DELETE

GET

POST

C

RPUT

DELETE

GET

POST

S

Page 25: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 25

2. Composite Representation

GET

DELETE

GET

POST

C

RPUT

DELETE

GET

POST

S

DMLinkG

LinkC

GETG

LinkD

Page 26: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 26

Demo

Page 27: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 27

Was it just a Mashup?

MashupREST

Composition

Mashup

(It depends on the definition of Mashup)

Page 28: Techniques for Composing REST services - JOpera

©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

Page 29: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 29

Read-only vs. Read/write

Simply aggregating data (feeds)

GET

GETC

RGET

S

Page 30: Techniques for Composing REST services - JOpera

©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

Page 31: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 31

Can you always do thisfrom a web browser?

Single-Origin Sandbox

Client

CompositeRESTfulservice

Origin Servers

Origin Servers

CompositeRepresentation

Page 32: Techniques for Composing REST services - JOpera

©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

Page 33: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 33

Complementary

Mashup RESTComposition

Mashup

Read-OnlyRead/Write

APIUI

SituationalReusable

ServiceSandboxed

Page 34: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 34

1. Defining RESTful service composition

2. Example: DoodleMap

3. What about mashups?

4. BPM and REST

RESTful Composition Techniques

Page 35: Techniques for Composing REST services - JOpera

©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

Page 36: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 36

RESTful Web Services APIs…

WSDL 1.1

…do not use WSDL 1.1

Page 37: Techniques for Composing REST services - JOpera

©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)

Page 38: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 38

BPMWorkflow

Languages

RESTfulWeb ServiceComposition

Page 39: Techniques for Composing REST services - JOpera

©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

Page 40: Techniques for Composing REST services - JOpera

©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)

Page 41: Techniques for Composing REST services - JOpera

©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>

Page 42: Techniques for Composing REST services - JOpera

©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

Page 43: Techniques for Composing REST services - JOpera

©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

Page 44: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 44

DoodleMap as RESTful workflow

Page 45: Techniques for Composing REST services - JOpera

©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

Page 46: Techniques for Composing REST services - JOpera

© 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

Page 47: Techniques for Composing REST services - JOpera

©2009 - Cesare Pautasso 47

Raj Balasubramanian, Benjamin Carlyle, Thomas Erl, Cesare Pautasso, SOA with REST, Prentice Hall, to appear in 2010