Questions tagged [ballerina]

For questions about the Ballerina programming language

Ballerina (sometimes referred to as "Ballerina lang" or “Ballerinalang”) is an open-source programming language for the cloud that makes it easier to use, combine, and create network services. Ballerina is designed and developed by WSO2 together with the open-source community.

Type system

Ballerina is a statically typed, concurrent programming language focusing on network interactions and structured data. It has all the general-purpose functionality expected of a modern programming language, but several distinctive aspects make it particularly suitable for its intended purpose.

Ballerina provides language constructs specifically for consuming and delivering network services. Its abstractions and syntax for concurrency and network interaction have been designed to closely correspond with sequence diagrams. This enables a bidirectional mapping for any Ballerina function between its textual representation in the syntax and its graphical representation as a sequence diagram.

Ballerina has a structural type system that is more flexible and allows for looser coupling than traditional statically typed languages. Ballerina's data types are designed to work particularly well with structured data over network interactions by providing first-class support for JSON, XML, tabular data, etc.

Ballerina platform

The Ballerina language has been designed in conjunction with the Ballerina platform, which provides comprehensive support for a module-based software development model, including versioning, dependency management, testing, documentation, building, and sharing.

Code to Cloud

Ballerina Code to Cloud is designed to allow developers to write code without thinking about the deployment platform. This dramatically simplifies the experience of developing and deploying Ballerina code in the cloud.

Ballerina compiler can read configuration files and other first-class cloud-related constructs in the source code and generate artifacts to deploy the code into different clouds. These artifacts can be Dockerfile, Docker image, Kubernetes YAML's, or serverless functions required to deploy the code into different clouds.

Library

The Ballerina language includes a lang library, which provides fundamental operations on the data types defined by the language. The Ballerina platform includes an extensive standard library, which consists of the usual low-level, general-purpose functionality and support for a wide variety of network protocols, interface standards, data formats, authentication/authorization standards, etc. It makes writing secure and resilient distributed applications significantly easier than with other languages.

Ballerina reference documentation

Get started tutorials

Other resources

469 questions
4
votes
1 answer

How to write a test case in Ballerina?

I'm a newbie to Ballerina integration language and need a way to write a test case. Following is my initial code. package samples.foo.bar; import ballerina.lang.system; function main (string[] args) { int i = addTwoNumbers(1, 2); …
Chanuka Ranaba
  • 635
  • 3
  • 12
  • 24
3
votes
0 answers

Error table was mutated after iterator created, although iterator and mutation are on different tables

error: {ballerina}IteratorMutabilityError {"message":"Table was mutated after the iterator was created"} at ballerina.lang.table.0:externNext(internal.bal:42) ballerina.lang.table.0.TableIterator:next(internal.bal:39) …
Tobega
  • 45
  • 5
3
votes
1 answer

Test failure when mocking nil result

When trying to run a test that mocks a nil return value, I'm getting the following error. Any idea? function f1() returns string?|error { return f2(); } function f2() returns string?|error { return "done"; } // --tests import…
Bondowe
  • 75
  • 4
3
votes
1 answer

Ballerina, Using Json Response from REST-API

My professor wants me to write a little tutorial on how to deploy Ballerina services. So I'm trying to learn it. I'm using Version 1.2 and I'm a bit overwhelmed by the concept of taint checking and the variable types... I'm trying to write a minimal…
3
votes
2 answers

Ballerina "type 'json' does not support field access for assignment"

I'm using the Ballerina language to create a RESTful web service for order management in an online retail store as instructed in here. In the resource function which handles HTTP PUT requests, there is a piece of code which will retrieve the…
3
votes
1 answer

Threads and Reactive Programming in Ballerina

I have just started to follow ballerina by reading https://ballerina.io/ documentation. when I try to run Hello World Parallel then I have no idea how internally it works? import ballerina/io; public function main() { @strand {thread:…
Nafaz M N M
  • 1,558
  • 2
  • 27
  • 41
3
votes
1 answer

Ballerina integrator and Elasticsearch

i am working on my bachelor degree project and i have to use the Ballerina integrator middle-ware. Now i need to make a service which will be able to index data coming to ballerina into Elasticsearch.Is there a way to communicate with Elasticsearch…
Under_Ice
  • 147
  • 5
3
votes
1 answer

Build size of a simple program

I do not understand why the size of a very simple compiled program is around 8Mb. This does not include the JVM I assume? Here is a simple Ballerina program import ballerina/io; type Score [string, int, int]; public type Person object { int…
Rudolf
  • 107
  • 1
  • 10
3
votes
1 answer

How do you get the type of a variable in Ballerina?

How do you get the type of a variable in Ballerina? I know that boolean checks are possible such as these below: import ballerina/io; public function main() { any x = "This is a test"; io:println(x is string); // Evaluates to true …
Rahul P
  • 2,493
  • 2
  • 17
  • 31
3
votes
2 answers

Ballerina annotation processing doesn't work as expected

I am trying to implement a simple annotation processor with ballerina (jBallerina-1.0.5 on MacOS Catalina). In this example, I need to: Iterate through available resource functions of a given service For each iteration, get values of a given…
Channa Jayamuni
  • 1,876
  • 1
  • 18
  • 29
3
votes
2 answers

Deploy Ballerina as AWS Lambda functions

I've written a basic Ballerina function and attempted to deploy as AWS Lambda. AWS reports a permissions error when I try to add the Lambda layer (using the published ARN link -…
Jeff Swan
  • 33
  • 3
3
votes
2 answers

Ballerina: How do connect with SMTP server and send email?

I am looking at WSO2's Ballerina programming language. I don't see the module or package that allows the ballerina code to call SMTP server and send email. The only thing close to SMTP is the Gmail connector, but that is not what I am looking for.…
chj915
  • 41
  • 2
3
votes
2 answers

How to invoke ballerina service in windows cmd

I'm running my services in ballerina composer, then I'm using Windows cmd to invoke the service using the curl but cmd is complaining that curl is not a recognized command. How could I do it in cmd? Please help.
MabutaBee
  • 57
  • 3
3
votes
1 answer

How to pass an endpoint as an parameter to a function in Ballerina

I'm using 'wso2/ftp' package for some file transferring process and have an ftp:Client endpoint as follows in my main .bal file. endpoint ftp:Client server1 { protocol: ftp:FTP, host:, port:21, secureSocket: { …
Nipuna Dilhara
  • 424
  • 2
  • 6
  • 18
3
votes
3 answers

Ballerina For Loop

Is there a for loop in ballerina like the for loop in java. I could only find foreach and while loop in the Ballerina Documentation. for(int i=0; i<10; i++){ //some logic }
Dan.M
  • 71
  • 1
1
2
3
27 28