Ballerina Composer — Flexible, powerful and Smartest ever graphical tool for composing your Ballerina Programs


Ballerina Programming Language

Ballerina is the next generation of general purpose programming languages which is concurrent, strongly typed mapped with both textual and graphical syntax. Ballerina is highly optimized to write programs to integrate with data sources, services, and network-connected APIs of all kinds. To get a more detailed insight about Ballerina (The Language for the the future of Integration :) ), refer You can download and give it a swirl and you’ll feel how cool it is.

Ballerina Composer

Now it’s time to get your dance choreographed with some style. That’s where Ballerina Composer come to the action. Ballerina Composer provides you a greater flexibility on writing your Ballerina Program. Ballerina composer can be introduced as the best and the most strongest graphical representation of a programming language. Ballerina Composer covers each and every corner of the Ballerina Lang.

Start Ballerina Composer

You can download the Ballerina Composer along with the tools we provide for Ballerina. You can download from our official site. Now extract the composer, and go to the bin directory, and run the script according to your Operating system.

Ballerina Composer Features

Now lets have a look at what Ballerina Composer makes it the best.

Language Constructs drag drop panel

You can easily drag and drop any supported, main language constructs from the construct panel from the left. I’ll describe each and construct in due course of this ballerina composer tutorial series.

As the first exposure to the Ballerina and the Composer, first of all, let’s create a simple echo service and try to explore some of the cooler than the absolute zero features of Ballerina composer ;) .

Lets identify what are the syntactical units we are going to use.

Tool Palette Main Constructs functions
  1. Service Definition
  2. Resource Definition
  3. Reply Statement
  4. Function Invocation Statement

First of all Let’s drag and drop a Service Definition construct from the tool palette. Basically You need at least one Resource Definition inside a service. By default You will have a single resource inside a service definition and you can drag and drop multiple resource definitions as per your requirements. Let’s configure our service and the resource first.

Default Service Definition

As you can see in the above picture, this is the default Service Definition structure in the Ballerina Composer, and inside the Service Definition container you can see the Resource Definition as well. By clicking on the red outlined areas you can change the name of the service and the resource.

Configure Service Annotations
Set Service Base Path

Select the parameter, configure and click on the plus sign to add it to the configuration

Adding the input arguments to the service

Click on the first icon on the right of the heading bar of Resource Definition and you can set the input arguments to the Resource. By default there is an argument of the type of message and this message content can be addressed at the resource level while we write the logic. You can apply various operations on the message (provided as the default argument). Also you can add other parameters as well, with the desired type (You can click on the drop down you can see the supported types).

Same as we did for the service, we can configure resource level annotations as well.

Configure the Resource Annotations
Resource Annotations

Now we have configured the Service and the Resource Definitions. Now let’s do some operation inside the Resource Definition on the incoming message to the resource. You can apply various operations on the passed message. Today I am going to use one of the default operations we can found at the tool palette. As shown on the functions above, there are number of default functions imported along with the package. You can drag and drop any of the function and configure them as you wish. For this example, I am going to use the function which allow us to convert the request message to an output message. drag the function and drop on the default worker of the service. You’ll see the following as the end result.

You can click on the box and edit the function (Here I change the message parameter to use our incoming message m.

Editing the Function Invocation

Now let’s add the Reply Statement next. Drag and drop the reply statement from the tool palette as shown in an above image (Tool Palette Main Constructs). Our final configuration looks as bellow.

Final Configuration

Voila! Now we have successfully completed our first Service we wrote with Ballerina. Now we are ready to run the service in the Ballerina Run time. Before that, let’s look at how this configuration looks like in the Ballerina syntax. You are one click ahead to convert our first Composer configuration to the Ballerina Language syntax. Click on the Source View button at the bottom right corner and you’ll directed to the source view.

Toggle to the Source view
Source view with the configuration’s Ballerina Syntax

We will look at the swagger view in one of the next tutorials (Fasten Your Seat Belts, The Journey has Just Begun :) )

Now we are all good to go ahead and run our service. You can save the configuration to the .bal configuration file or you can run the server via the composer. Let’s use the full capabilities of the composer :) ?

If we are going to run it via the composer, you need to start the Ballerina Run time and set the BALLERINA_HOME first. You can Download the Ballerina Runtime from Downloads. Download, extract and go to the <BALLERINA_DIR>/bin and run the script according to your Operating system. Now set BALLERINA_HOME to Your Ballerina Runtime directory.

Now we start the composer as we mentioned earlier of this tutorial.

Running the Ballerina Service with Composer

Left to the Tool palette, you can find the following and click on the highlighted options to deploy the service and start it.

Run the Service
Service is Running

Now the service is up and running on port 9090. You can invoke the service with the following Url.

http://localhost:9090/echoservice/test .

Send a POST to the above endpoint Url and you’ll see our first Ballerina Service echo the same Payload we sent.

As the first step we could successfully compose, deploy and invoke our first Ballerina configuration. You can find more about the Ballerina syntax on our official site and help us improve by reporting any issue you face.


Ballerina Composer

With our next tutorial, let’s explore more about how cool Ballerina Composer to programming with Ballerina.