Ballerina for beginners

Meruja Selvamanikkam
3 min readAug 8, 2019

--

I hope this article will be helpful for those who are newbies to a ballerina. I will be discussing the fundamentals of Ballerina language and posting a tweet on twitter through our personal account using Ballerina. Since I am a beginner to Ballerina, trying to express the background of Ballerina in my understanding.

Before we dive in detail, let's see what is Ballerina?

It is a cloud-native programming language. Ballerina makes it easy to write micro-services that integrates APIs. There are many vendors to come up with a solution to real-world problems. But the common problem that all vendors face is integrating APIs used for micro-services. That is, connecting systems together. Even if we go with Java or Go or C++, implementing the solution is easier than integrating. But Ballerina helps to integrate with few lines of code. Most of the programming languages are typed with textual, in addition to that Ballerina provides graphical syntaxes.

Getting Started Ballerina for OS X…….

First, download the package file for the OS X. Once you double-click on the downloaded package. It prompts the installer.

For OS X, you do not need to set up the path Environmental variable. It will automatically be done by the installer.

Ballerina installer

After the installation

  1. Open the terminal
  2. Navigate to the directory where you have ballerina home pack.
  3. Issue the command “ballerina init” to initialize ballerina.

There are plenty of examples available to understand the language completely. Refer this link for examples.

Why Ballerina????

Ballerina is different from other languages but it is designed to make c/c++/c#/java/javascript programmers feel comfortable. Hence we can say that it is a programmer-friendly language. Ballerina is a strong language to invoke services. For all program, there will be a sequence diagram to understand the flow, message passing, and service integration. Also, Ballerina is not just a language, but it has a standard ecosystem, which includes a standard library, a repository, test infrastructure, and documentation system.

Tweeting using Ballerina

Final code for twitter config ()

For the twitter credentials, create a new file twitter.toml and store Client Id, Client Secret, Access token and Access tokens secret.

twitter.toml

Copy your credentials from your twitter app which will in the form of alphanumeric characters.

Once you finish the service file and twitter file.

  1. Navigate to the directory where you have the service, twitter files in the terminal.
  2. Issue the following command: “$ ballerina run — config twitter.toml hello_service.bal” to initiate the service.
  3. Then, in another terminal issue cURL command “$ curl -d “Ballerina” -X POST localhost:9090/”.
  4. You can customize the tweet by simply replacing “Ballerina ” and run the command.
  5. The terminal will indicate the successful tweet by showing the tweet id. Also, you can check your twitter app.
Twitter post using Ballerina

--

--

Meruja Selvamanikkam

I am a Research Assistant at University of Alberta. I graduated from UofA with MSc in Medical Sciences.