Business Process Management
          with REST
                Cesare Pautasso
             Faculty of Informatics
        University of Lugano, Switzerland

              c.pautasso@ieee.org
           http://www.pautasso.info
                   @pautasso
BPM       REST

©2010 - Cesare Pautasso          2
Business
                            RESTful
           Process
                          Web Services
          Management



©2010 - Cesare Pautasso                  3
WS-* Standards Stack




©2009-2010 - Cesare Pautasso - 30.6.2010   4
WS-* Standards Stack

                                   BPM                              Management
    Interoperability




                                                                      Transactions
                                                         Security
                                           Reliability
                       Metadata




                                                                                     State
                                                         Messaging

©2009-2010 - Cesare Pautasso - 30.6.2010                                                     5
BPM                       Management
    Interoperability




                                                              Transactions
                                                 Security
                                   Reliability
                       Metadata




                                                                             State
                                     Messaging
                                   Can you do     it
                                        with REST?
©2010 - Cesare Pautasso                                                              6
From REST-* (JBoss)



        “    We believe there is huge potential to




                                                        http://www.jboss.org/reststar/specifications/workflow.html
          marrying REST with workflow and BPM.
                              […]
          Combined with the architecture of the Web,
          a workflow service can provide both a truly
          simple, portable, and flexible way to build
          workflow driven integrations and


                          ”
          applications.




©2010 - Cesare Pautasso                                             7
Business Process Management
             BPMN/WS-BPEL
                                                           Workflow        Workflow
                           Process Model                   Users/Clients   Participants
                          Act 2      Act 4

         Act 1                       Act 5       Act 7

                          Act 3      Act 6

                                                    Workflow Management Engine
                   Workflow
                   Modelers
                                    Adapters                                        Bus

                                  Applications                                   Web
                                                                                 Services

                                           Databases


©2010 - Cesare Pautasso                                                                     8
WS-BPEL Primitives

                              Web      <receive>
            <invoke>
                             Service    <reply>


            <invoke>          Web
                                       <receive>
                             Service

      The modeling language natively supports
       the RPC or message-based connectors

©2010 - Cesare Pautasso                            9
What is your SOA connector today?

                          RPC           ESB



                                REST/HTTP



©2010 - Cesare Pautasso                       10
REST as a new connector

                          RPC                 ESB
                                         Publish/Subscribe
                          Call


                                 REST/HTTP

                             Get/Put/Post/Delete


©2010 - Cesare Pautasso                                      11
Is REST really used?
                                                      Atom, 2%
                                                       Gdata, 1%
                                       XMPP, 0%
                                                           JavaScript, 6%
                                     XML-RPC, 2%
                          SOAP, 17%                         JSON-RPC, 0%


                                SMS,                                        2042 APIs
                                 0%
                           RSS, 1%
                                                                   ProgrammableWeb.com
                                                                            30.6.2010
                                                   REST,
                                                   71%

©2010 - Cesare Pautasso                                                                 12
REST in one slide
  Web Services expose their
   data and functionality trough      PUT
   resources identified by URI
                                            R
  Uniform Interface Principle:        GET
   Clients interact with resources       POST
   through a fix set of verbs.                   DELETE
   Example HTTP:
   GET (read), PUT (update), DELETE, POST (catch all),
  Multiple representations for the same resource
  Hyperlinks model resource relationships and valid
   state transitions for dynamic protocol description
   and discovery
©2010 - Cesare Pautasso                                   13
Business Process Management
                                                            Workflow        Workflow
                           Process Model                    Users/Clients   Participants
                          Act 2      Act 4

         Act 1                       Act 5        Act 7

                          Act 3      Act 6

                                             RESTful Workflow Management Engine

 PUT


   GET
                 R                  Adapters                                         Bus

                                  Applications                                    Web
                                                                                  Services
        POST
                            DELETE         Databases


©2010 - Cesare Pautasso                                                                      14
BPM with REST

                           Process Model
                                                                      Publishing
                          Act 2    Act 4                          R   Processes
         Act 1                     Act 5        Act 7
                                                                      as Resources
                          Act 3    Act 6

                                           RESTful Workflow Management Engine




                                                                   RESTful
                                                                   Service
                                  R             R           R      Composition

©2010 - Cesare Pautasso                                                          15
BPM with REST
                                                         Publishing
            This talk will                           R   Processes
             focus here                                  as Resources

                              RESTful Workflow Management Engine




                                                      RESTful
                                                      Service
                          R        R           R      Composition

©2010 - Cesare Pautasso                                             16
Some Challenges for BPM engines
   Can you drive the execution of tasks with
    PUT/POST/DELETE requests?
   Can you monitor your processes with an
    RSS/ATOM feed?
   Can you bookmark a process instance?
   Can you send an email to your colleague with a
    link to a task from your worklist?
   Can you ask a process to give you links to its
    tasks left to be done?
   Can you publish your process as a resource?
   Can you publish resources from your process?
   Can you call RESTful APIs directly?
©2010 - Cesare Pautasso                              17
BPM         REST
    Processes             Resources/URIs
    Tasks                 Uniform
    Control Flow           Interface
    Data Flow             Representations
   …                      Hypermedia

©2010 - Cesare Pautasso                       18
Everything is a resource
                   /process/X       /process/X/1

                                      Process
                          Process
                                     Instance



                                       Task
                           Task
                                     Instance
                     /task/Y
                                    /task/Y/1


©2010 - Cesare Pautasso                            19
Hypermedia
                          /process                               Process
                                                      Process
                                                                Instance
         GET
                          /process/name                           Task
                                                       Task
                                                                Instance
          GET
                          /process/name/instance

          GET
                          /process/name/instance/taskname


             Follow links to discover the processes
                     deployed as resources
©2010 - Cesare Pautasso                                                    20
Representations
    Web page
with form to start                                                     List of process
 a new process                                                       input parameters
    instance       ContentType:                       ContentType:

                           text/html application/xml
                                    GET /process/name
                     ContentType:                              ContentType:
                 text/plain                             application/json
                                       ContentType:
   Basic textual                                                         Process
    description                     image/svg+xml                        metadata
  of the process                                                          in JSON

©2010 - Cesare Pautasso                                                              21
Uniform Interface and Hypermedia
                                      List the
               GET /process          deployed            Get a form
                                     processes         describing how
                GET /process/name                        to start the
                                                           process
                                             Start a new
                POST /process/name             process
                                              instance Check what
                                                          is the state
                GET /process/name/instance                    of the
                                                            instance
                 DELETE /process/name/instance
                                                         Clean up
                                                      (once it is done)
©2010 - Cesare Pautasso                                                   22
Starting or Running a new process?
                                /process    Should the client be kept
                                             waiting for the process to run
                                             until completion?
               POST /process




                            200 OK          Clients may want to block until
                          (Process           the whole process has
                          Finished           completed its execution
                            Reply)           (or it decides to reply to them)
©2010 - Cesare Pautasso                                                       23
Starting or Running a new process?
                              /process    The client starting a long
                                           running process is redirected to
                                           a location x representing the
               POST /process               newly started process instance
                                          The process and the client run
              202 Accepted                 asynchronously
              Location: x
                                          The client may retrieve the
                                           current state of the process
            GET /process/x                 instance at any time

                          200 OK




©2010 - Cesare Pautasso                                                  24
Uniform Interface and Hypermedia
               GET /task            List the
                                  active tasks          Get a form
                                                      describing how
                GET /task/name/instance               to perform the
                                                           task
                                                  Finish
                POST /task/name/instance
                                                 the task


                GET /task/name/instance               Get the final
                                                    representation
                                                   of the completed
                 …                                        task

©2010 - Cesare Pautasso                                                25
POST or PUT?
               GET /task                          Note:
                                           PUT could also be
                                               used here
                GET /task/name/instance     to set the state
                                           (Finished, Failed)
                                               of the task
                POST /task/name/instance


                GET /task/name/instance


                 …

©2010 - Cesare Pautasso                                         26
Example: RESTBucks




Jim Webber, Savas Parastatidis, Ian Robinson   http://restinpractice.com/ 27
Simple RESTBucks Example

                                            POST
  /rest/restbucks/order/1.0/
  /rest/restbucks/order/1.0/{id}
                 GET
   /tasks/restbucks/order/1.0/{id}/payment

                                    POST
                   GET



                          /receipt/{uuid}


©2010 - Cesare Pautasso                            28
Simple RESTBucks Example
  Hypermedia-centric service design (and implementation)
  done with a business process model




                                                           Private Tasks
   Resources




©2010 - Cesare Pautasso                                                29
Instantiating a process
    GET /rest/restbucks/order/1.0/




 Retrieve a form which describes how to instantiate a new process
©2010 - Cesare Pautasso                                             30
Instantiating a process
    POST /rest/restbucks/order/1.0/




                            Run = blocking
                            (client waits until
     Start = non blocking   the process replies)
     (redirect to URI of
     the new instance)
©2010 - Cesare Pautasso                            31
Interacting with a task
    GET
    /task/restbucks/order/1.0/0/payment




©2010 - Cesare Pautasso                   32
Interacting with a task
  POST /rest/restbucks/order/1.0/0/payment




©2010 - Cesare Pautasso                  33
Interacting with a resource
  GET /receipt/2fc7f6e2-8b43-4672-a7c4…




©2010 - Cesare Pautasso                   34
Interacting with a resource
  DELETE /rest/restbucks/order/1.0/0




©2010 - Cesare Pautasso                35
Deleting a process resource
  DELETE /rest/restbucks/order/1.0/0




©2010 - Cesare Pautasso                36
Viewpoints



                          Control        Data
                           Flow          Flow
                              Service
                              Bindings

     REST.TASK REST.URI         REST     WS-*   SQL   …
©2010 - Cesare Pautasso                                   37
Control
      Flow



           Control Flow
           Dependency




©2010 - Cesare Pautasso   38
Service
   Bindings


              SQL

             WS-*

             REST

         REST.URI

       REST.TASK


©2010 - Cesare Pautasso   39
REST.TASK




                          Specify the final state
                          of the Payment task



©2010 - Cesare Pautasso                             40
REST.URI




                          Specify the state
                          associated with the URI


©2010 - Cesare Pautasso                             41
Data
         Flow



               Data Flow
               (Copy)




©2010 - Cesare Pautasso    42
©2010 - Cesare Pautasso   43
Static vs. Dynamic Typing
      Myth: RESTful Web services cannot be
       composed (with BPEL) because they do
       not give a static contract description
      Reality: RESTful Web services can
       dynamically negotiate the most
       suitable representation format with
       their clients
      Challenge: How to support dynamic
       typing and content type negotiation in a
       BPM composition language?

©2010 - Cesare Pautasso                           44
Active Resources
      Myth: Processes cannot be mapped to
       resources because they can change
       their state (independently of their
       clients)
      Reality: REST Resources do not have to
       be passive “CRUD” services but can be
       active and have a life of their own.
      Challenge: How to best let clients
       control an active resource backed up
       by a process instance through the
       uniform interface?
©2010 - Cesare Pautasso                         45
Synchronous vs. Asychronous
      Myth: Processes run for a long time
       and need to interact asynchronously
       with their clients. This cannot be done
       with HTTP.
      Reality: HTTP supports non blocking
       interactions. Each process instance is
       mapped to a resource URI, which can
       be used by clients throughout its
       lifetime.
      Challenge: How to let processes send
       notifications back to their clients?
©2010 - Cesare Pautasso                          46
Conclusions
      REST resources are a good abstraction
       to publish processes on the Web
      RESTful HTTP is good enough to
       interact without any extension with
       process execution engines and drive
       the execution of process and task
       instances
      If done right, BPM can be a great
       modeling tool for Hypermedia-centric
       service design
       (and implementation!)
©2010 - Cesare Pautasso                        47
More Information

     Cesare Pautasso
     Faculty of Informatics, USI Lugano
     http://www.pautasso.info/
     @pautasso

     JOpera
     RESTful Process Engine
     http://www.jopera.org/
     @jopera_org
©2010 - Cesare Pautasso                   48
References
     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.
©                                                                     49
Conclusion

                                     Raj Balasubramanian,
         Applying the SOA composition principle to
                                     Benjamin Carlyle,
                                     Thomas Erl,
          REST gives interesting results Pautasso,
                                     Cesare
         Thanks to hyperlinks, REST SOA with a new
                                      brings REST,
          (more dynamic and loosely coupled)
                                     Prentice Hall,
          twist to SOA composition to appear in 2011
      Composing RESTful services helps to build
       mashups, but is different
      A RESTful API is the perfect abstraction for
       publishing the state of a workflow


©2010 - Cesare Pautasso                                     50

BPM with REST

  • 1.
    Business Process Management with REST Cesare Pautasso Faculty of Informatics University of Lugano, Switzerland c.pautasso@ieee.org http://www.pautasso.info @pautasso
  • 2.
    BPM REST ©2010 - Cesare Pautasso 2
  • 3.
    Business RESTful Process Web Services Management ©2010 - Cesare Pautasso 3
  • 4.
    WS-* Standards Stack ©2009-2010- Cesare Pautasso - 30.6.2010 4
  • 5.
    WS-* Standards Stack BPM Management Interoperability Transactions Security Reliability Metadata State Messaging ©2009-2010 - Cesare Pautasso - 30.6.2010 5
  • 6.
    BPM Management Interoperability Transactions Security Reliability Metadata State Messaging Can you do it with REST? ©2010 - Cesare Pautasso 6
  • 7.
    From REST-* (JBoss) “ We believe there is huge potential to http://www.jboss.org/reststar/specifications/workflow.html marrying REST with workflow and BPM. […] Combined with the architecture of the Web, a workflow service can provide both a truly simple, portable, and flexible way to build workflow driven integrations and ” applications. ©2010 - Cesare Pautasso 7
  • 8.
    Business Process Management BPMN/WS-BPEL Workflow Workflow Process Model Users/Clients Participants Act 2 Act 4 Act 1 Act 5 Act 7 Act 3 Act 6 Workflow Management Engine Workflow Modelers Adapters Bus Applications Web Services Databases ©2010 - Cesare Pautasso 8
  • 9.
    WS-BPEL Primitives Web <receive> <invoke> Service <reply> <invoke> Web <receive> Service  The modeling language natively supports the RPC or message-based connectors ©2010 - Cesare Pautasso 9
  • 10.
    What is yourSOA connector today? RPC ESB REST/HTTP ©2010 - Cesare Pautasso 10
  • 11.
    REST as anew connector RPC ESB Publish/Subscribe Call REST/HTTP Get/Put/Post/Delete ©2010 - Cesare Pautasso 11
  • 12.
    Is REST reallyused? Atom, 2% Gdata, 1% XMPP, 0% JavaScript, 6% XML-RPC, 2% SOAP, 17% JSON-RPC, 0% SMS, 2042 APIs 0% RSS, 1% ProgrammableWeb.com 30.6.2010 REST, 71% ©2010 - Cesare Pautasso 12
  • 13.
    REST in oneslide  Web Services expose their data and functionality trough PUT resources identified by URI R  Uniform Interface Principle: GET Clients interact with resources POST through a fix set of verbs. DELETE Example HTTP: GET (read), PUT (update), DELETE, POST (catch all),  Multiple representations for the same resource  Hyperlinks model resource relationships and valid state transitions for dynamic protocol description and discovery ©2010 - Cesare Pautasso 13
  • 14.
    Business Process Management Workflow Workflow Process Model Users/Clients Participants Act 2 Act 4 Act 1 Act 5 Act 7 Act 3 Act 6 RESTful Workflow Management Engine PUT GET R Adapters Bus Applications Web Services POST DELETE Databases ©2010 - Cesare Pautasso 14
  • 15.
    BPM with REST Process Model Publishing Act 2 Act 4 R Processes Act 1 Act 5 Act 7 as Resources Act 3 Act 6 RESTful Workflow Management Engine RESTful Service R R R Composition ©2010 - Cesare Pautasso 15
  • 16.
    BPM with REST Publishing This talk will R Processes focus here as Resources RESTful Workflow Management Engine RESTful Service R R R Composition ©2010 - Cesare Pautasso 16
  • 17.
    Some Challenges forBPM engines  Can you drive the execution of tasks with PUT/POST/DELETE requests?  Can you monitor your processes with an RSS/ATOM feed?  Can you bookmark a process instance?  Can you send an email to your colleague with a link to a task from your worklist?  Can you ask a process to give you links to its tasks left to be done?  Can you publish your process as a resource?  Can you publish resources from your process?  Can you call RESTful APIs directly? ©2010 - Cesare Pautasso 17
  • 18.
    BPM REST  Processes  Resources/URIs  Tasks  Uniform  Control Flow Interface  Data Flow  Representations …  Hypermedia ©2010 - Cesare Pautasso 18
  • 19.
    Everything is aresource /process/X /process/X/1 Process Process Instance Task Task Instance /task/Y /task/Y/1 ©2010 - Cesare Pautasso 19
  • 20.
    Hypermedia /process Process Process Instance GET /process/name Task Task Instance GET /process/name/instance GET /process/name/instance/taskname Follow links to discover the processes deployed as resources ©2010 - Cesare Pautasso 20
  • 21.
    Representations Web page with form to start List of process a new process input parameters instance ContentType: ContentType: text/html application/xml GET /process/name ContentType: ContentType: text/plain application/json ContentType: Basic textual Process description image/svg+xml metadata of the process in JSON ©2010 - Cesare Pautasso 21
  • 22.
    Uniform Interface andHypermedia List the GET /process deployed Get a form processes describing how GET /process/name to start the process Start a new POST /process/name process instance Check what is the state GET /process/name/instance of the instance DELETE /process/name/instance Clean up (once it is done) ©2010 - Cesare Pautasso 22
  • 23.
    Starting or Runninga new process? /process  Should the client be kept waiting for the process to run until completion? POST /process 200 OK  Clients may want to block until (Process the whole process has Finished completed its execution Reply) (or it decides to reply to them) ©2010 - Cesare Pautasso 23
  • 24.
    Starting or Runninga new process? /process  The client starting a long running process is redirected to a location x representing the POST /process newly started process instance  The process and the client run 202 Accepted asynchronously Location: x  The client may retrieve the current state of the process GET /process/x instance at any time 200 OK ©2010 - Cesare Pautasso 24
  • 25.
    Uniform Interface andHypermedia GET /task List the active tasks Get a form describing how GET /task/name/instance to perform the task Finish POST /task/name/instance the task GET /task/name/instance Get the final representation of the completed … task ©2010 - Cesare Pautasso 25
  • 26.
    POST or PUT? GET /task Note: PUT could also be used here GET /task/name/instance to set the state (Finished, Failed) of the task POST /task/name/instance GET /task/name/instance … ©2010 - Cesare Pautasso 26
  • 27.
    Example: RESTBucks Jim Webber,Savas Parastatidis, Ian Robinson http://restinpractice.com/ 27
  • 28.
    Simple RESTBucks Example POST /rest/restbucks/order/1.0/ /rest/restbucks/order/1.0/{id} GET /tasks/restbucks/order/1.0/{id}/payment POST GET /receipt/{uuid} ©2010 - Cesare Pautasso 28
  • 29.
    Simple RESTBucks Example Hypermedia-centric service design (and implementation) done with a business process model Private Tasks Resources ©2010 - Cesare Pautasso 29
  • 30.
    Instantiating a process GET /rest/restbucks/order/1.0/ Retrieve a form which describes how to instantiate a new process ©2010 - Cesare Pautasso 30
  • 31.
    Instantiating a process POST /rest/restbucks/order/1.0/ Run = blocking (client waits until Start = non blocking the process replies) (redirect to URI of the new instance) ©2010 - Cesare Pautasso 31
  • 32.
    Interacting with atask GET /task/restbucks/order/1.0/0/payment ©2010 - Cesare Pautasso 32
  • 33.
    Interacting with atask POST /rest/restbucks/order/1.0/0/payment ©2010 - Cesare Pautasso 33
  • 34.
    Interacting with aresource GET /receipt/2fc7f6e2-8b43-4672-a7c4… ©2010 - Cesare Pautasso 34
  • 35.
    Interacting with aresource DELETE /rest/restbucks/order/1.0/0 ©2010 - Cesare Pautasso 35
  • 36.
    Deleting a processresource DELETE /rest/restbucks/order/1.0/0 ©2010 - Cesare Pautasso 36
  • 37.
    Viewpoints Control Data Flow Flow Service Bindings REST.TASK REST.URI REST WS-* SQL … ©2010 - Cesare Pautasso 37
  • 38.
    Control Flow Control Flow Dependency ©2010 - Cesare Pautasso 38
  • 39.
    Service Bindings SQL WS-* REST REST.URI REST.TASK ©2010 - Cesare Pautasso 39
  • 40.
    REST.TASK Specify the final state of the Payment task ©2010 - Cesare Pautasso 40
  • 41.
    REST.URI Specify the state associated with the URI ©2010 - Cesare Pautasso 41
  • 42.
    Data Flow Data Flow (Copy) ©2010 - Cesare Pautasso 42
  • 43.
    ©2010 - CesarePautasso 43
  • 44.
    Static vs. DynamicTyping  Myth: RESTful Web services cannot be composed (with BPEL) because they do not give a static contract description  Reality: RESTful Web services can dynamically negotiate the most suitable representation format with their clients  Challenge: How to support dynamic typing and content type negotiation in a BPM composition language? ©2010 - Cesare Pautasso 44
  • 45.
    Active Resources  Myth: Processes cannot be mapped to resources because they can change their state (independently of their clients)  Reality: REST Resources do not have to be passive “CRUD” services but can be active and have a life of their own.  Challenge: How to best let clients control an active resource backed up by a process instance through the uniform interface? ©2010 - Cesare Pautasso 45
  • 46.
    Synchronous vs. Asychronous  Myth: Processes run for a long time and need to interact asynchronously with their clients. This cannot be done with HTTP.  Reality: HTTP supports non blocking interactions. Each process instance is mapped to a resource URI, which can be used by clients throughout its lifetime.  Challenge: How to let processes send notifications back to their clients? ©2010 - Cesare Pautasso 46
  • 47.
    Conclusions  REST resources are a good abstraction to publish processes on the Web  RESTful HTTP is good enough to interact without any extension with process execution engines and drive the execution of process and task instances  If done right, BPM can be a great modeling tool for Hypermedia-centric service design (and implementation!) ©2010 - Cesare Pautasso 47
  • 48.
    More Information Cesare Pautasso Faculty of Informatics, USI Lugano http://www.pautasso.info/ @pautasso JOpera RESTful Process Engine http://www.jopera.org/ @jopera_org ©2010 - Cesare Pautasso 48
  • 49.
    References  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. © 49
  • 50.
    Conclusion Raj Balasubramanian,  Applying the SOA composition principle to Benjamin Carlyle, Thomas Erl, REST gives interesting results Pautasso, Cesare  Thanks to hyperlinks, REST SOA with a new brings REST, (more dynamic and loosely coupled) Prentice Hall, twist to SOA composition to appear in 2011  Composing RESTful services helps to build mashups, but is different  A RESTful API is the perfect abstraction for publishing the state of a workflow ©2010 - Cesare Pautasso 50