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
3
votes
4 answers

How do I do a type check in ballerina

I tried if(string? myStr) but that gives a syntax error in the editor. How do I do a type check in Ballerina ?
nuwanbando
  • 601
  • 4
  • 5
3
votes
2 answers

Getting the status of a transaction without callbacks in Ballerina

In Ballerina we can identify whether a transaction was successful within "onCommit" and "onAbort" functions we provide. But this takes us away from the current method. I want to be able to verify whether the transaction was successful or failed in…
Erandi Ganepola
  • 303
  • 3
  • 12
3
votes
2 answers

Deploying the Ballerina integration example in a Docker container

On the Ballerina Quick Tour page, there is an example on deploying a previously created integration microservice (which is supposed to send a Tweet) within in a docker container. However, that part of the documentation doesn't describe how to…
Chathura Kulasinghe
  • 2,640
  • 5
  • 23
  • 23
3
votes
3 answers

How to terminate Ballerina program

I wanna stop ballerina program in the middle of some logic. How can I stop a running program in ballerina using code? I'm looking for something equivalent to System.exit(0) in java.
Isuru Gunawardana
  • 2,847
  • 6
  • 28
  • 60
3
votes
1 answer

How do I pass a variable into a ballerina worker?

I'm trying to refactor some code to be inside a worker and getting an error: undefined symbol userId Seems the worker is unable to see variables from the scope above it. How can I get the worker to see the parameter being passed in? import…
geekaholic
  • 31
  • 2
2
votes
1 answer

How to Add a Custom Field to an HTTP Return Record Type in Ballerina

I want to add a custom id field as part of the HTTP body. Here is my code that works, But this is not type-safe, since id is open to anydata and easy to make mistakes. import ballerina/http; service on new http:Listener(9090) { resource…
2
votes
1 answer

How to execute a SQL statement with `Like` operator in Ballerina

Need to execute a SQL statement with like operator in Ballerina. Plain SQL sample statement: SELECT * FROM albums where title like '%mon%'; How can we pass a variable value to such a query in Ballerina SQL client?
Anupama Pathirage
  • 631
  • 2
  • 10
  • 22
2
votes
0 answers

Getting a Ballerina Build warning detected conflicting jars

I'm getting the following warning and how can I get rid of it? Generating executable warning: Detected conflicting jar files: 'netty-buffer-4.1.86.Final.jar' dependency of 'ballerinax/redis' conflict with…
Chanuka Ranaba
  • 635
  • 3
  • 12
  • 24
2
votes
0 answers

Cannot access readonly class attributes inside an isolated function in Ballerina

I have two service classes Astronaut and Mission. Those are interrelated, and I'm trying to make them isolated. I get the following compilation error invalid access of mutable storage in an 'isolated' function How does self instance of readonly…
Ishad
  • 121
  • 1
  • 11
2
votes
1 answer

Ballerina: How can I search for a record in a table?

I am just learning Ballerina (I imagine we all are still at this point). I am trying to do this JSON Exercism exercise. There are probably other ways to do it, but I would like to solve it in the following way, because I think this is generally…
Mike Williamson
  • 4,915
  • 14
  • 67
  • 104
2
votes
3 answers

How do I Connect to MongoDB Atlas cluster from Ballerina?

I have been trying to connect to a cluster in MongoDB Atlas using the mongodb:Client. I am not able to find any connection string that is supported by the Ballerina client. I could not find any sample code that suggests how to do so. Following is…
2
votes
1 answer

Unable to pass dynamic values to config records

I have a requirement to pass a JWT client assertion to the oauth2 client credentials grant config record. I'm passing the parameter as the optional parameter. But this parameter has to be generated each time the token endpoint is called for an…
Thishani Lucas
  • 550
  • 1
  • 3
  • 21
2
votes
1 answer

How to add a new line within the string backtick template?

How can we have a new line within the string backtick template? For example the new line is not appearing in string backtick template of the following code. import ballerina/io; public function main() { string s1 = string`This is first line \n…
Anupama Pathirage
  • 631
  • 2
  • 10
  • 22
2
votes
2 answers

Remove duplicate values in string array?

There is a string array containing a number of strings in which multiple strings resemble each other. The requirement is to remove duplicates in the array. Input : ["Anne", "Jane", "John", "Jane", "Ivan", "Peter",…
Anupama Pathirage
  • 631
  • 2
  • 10
  • 22
2
votes
1 answer

Type inclusion for records changes CSV output

Consider the following valid Ballerina program that maps two identical data structures to CSV with io:fileWriteCsv: import ballerina/io; type Base record {| int base1; int base2; |}; type Derived1 record {| *Base; int derived1; …
user272735
  • 10,473
  • 9
  • 65
  • 96
1 2
3
27 28