1. 安装
直接下载对应操作系统的二进制文件即可,同时官方也提供了linux 操作系统对应的各种发行包(deb, rpm)
2. 基本代码
// Packages contain functions, annotations and connectors.
// This package is referenced by ‘http’ namespace in the code
// body.
import ballerina/http;
import ballerina/io;
// A service is a network-accessible API. This service
// is accessible at '/hello', and bound to a the listener on
// port 9090. `http:Service`is a connector in the `http`
// package.
service<http:Service> hello bind { port: 9090 } {
// A resource is an invokable API method.
// Accessible at '/hello/sayHello’.
// 'caller' is the client invoking this resource.
sayHello (endpoint caller, http:Request request) {
// Create object to carry data back to caller.
http:Response response = new;
// Objects have function calls.
response.setTextPayload("Hello Ballerina!\n");
// Send a response back to caller.
// Errors are ignored with '_'.
// ‘->’ is a synchronous network-bound call.
_ = caller -> respond(response);
}
}
备注:第一眼看上去,代码还是很清晰的,也比较简单
3. 运行
ballerina run app.bal
备注: 很简单,就是可能启动会稍微有点慢
4. 访问
结果:
HTTP/1.1 200 OK
content-type: text/plain
content-length: 17
server: ballerina/0.970.1
date: Mon, 14 May 2018 10:01:38 +0800
Hello Ballerina!
5. 总结
从官方介绍的特性来说还是很不错的,同时开发团队也提供了主流编辑器的可用插件,vscode idead 。。。
开发也比较简单,总的来说还是比较看好,具体的性能测试,目前暂时没有看到相关的结果,比较期待。