DEV Community


Posted on

Integrating Rest API with BPMN

In previous article, we learned about how to create BPMN and set up an environment. If you have not gone through yet, follow this link:

At the end of this article, you will be able to write your own BPMN and integrate with REST API.

Let’s get started!

As we have already downloaded bpm spring boot project , Lets add below dependency in pom.xml to make use of Groovy scripting in BPMN.

Enter fullscreen mode Exit fullscreen mode

We have below BPMN with us which we created in previous article. Now let’s integrate it with Business logic.

Image description

T1 is the service task which can be used to integrate with REST APIs.

In Camunda modeler, Click on T1 and expand Properties panel which is present in right middle.
In properties panel we can see id, name, Implementation dropdown. Leave id and name as is and click on Implementation dropdown.

Image description

Choose “Connector” option to integrate Rest API. Upon selection, the link “Must Configure Connector” will appear.

Image description

Click on the link and you will be directed to the next tab.
Before filling the values, lets checkout the fields here.

  • Connector-id: We can provide “http-connector” for REST call integration and “soap-http-connector” for Soap call integration.

  • Input parameters: These are the parameters required to make the REST call.
    url – End point of REST API
    method – HTTP method (ex. GET, POST, PATCH, PUT, DELETE etc.)
    headers – HTTP headers
    payload – Request payload (Not applicable for GET method)

Now that you understood these input parameters, click on the “+” symbol next to Input parameters and fill the values as shown in below screenshots:

Image description

Image description

Image description

Output parameters: These are the parameters we are expecting to receive from the REST API.

  • statusCode – HTTP status code which denotes the request status (ex. 200, 201, 500)
  • headers – HTTP response headers
  • response – response body returned from REST API.

Let’s fill output parameters as shown in below screenshot.

Image description

Now that REST API is integrated and we have response for Checking ticket availability, We can write the logic and add condition to our sequence flow.
Add one more output parameter and store the variable with the result (preferably Boolean).

Image description

Use this variable and add condition in the Sequence flow.

Image description

We have used conditionType as Expression which will be of below format:
Format: ${conditions}
Ex. ${condition1 && condition2 || condition3}

As for second “Ticket Not available” sequence, we can either add negative condition of same flag or we can set it as default sequence flow.
Sequence flow which is marked as Default will be chosen if no other sequence flow(s) conditions are met.

Image description

Now for our T2 task, as it is script task, we can incorporate any business logic. Instead of directly integrating REST API from bpm, if we choose to do it in microservice layer, we can write the code to make Rest call in our microservice class and invoke it from bpm.

Checkout below script. utilityClass is the object of the class which contains method bookTicket.

Image description

In other script tasks T3, T4, T5, Lets simply put print statements.
Image description

How to deploy BPMN in the engine:

If you have not yet integrated the BPMN with REST API, make all the tasks as script tasks and add some print statements and try deploying it engine in by following below steps.

  1. Place the BPMN in src/main/resources folder in the Spring boot microservice.
  2. Start the microservice. All the BPMNS placed in src/main/resources will be deployed into engine automatically.
  3. Open Camunda GUI URL: http://localhost:8080/service/demo/rest/camunda/app/welcome/default/#!/welcome
  4. Login with default username and password configured in the application.yaml file
  5. Click on cockpit

Under process definition, we can see the processes deployed. Currently we can see 1 process deployed.

Image description
On click of the process name, we can see the BPMN we created.

Image description

We can debug running and failed process instances here along with error message.
Take your time and explore the options here in GUI.

Hope you understood how to integrate REST API with BPMN in this article. Let’s see about more notations and its usages and also how to start process instance in the next article.

Happy Learning! 😊

Top comments (0)