Content deleted Content added
GoingBatty (talk | contribs) m General fixes and manual cleanup, typo(s) fixed: Github → GitHub |
Update hello world example to Ballerina 2201.0.0 version |
||
Line 42:
== Examples ==
=== Hello World
The regular Hello World program:
{{pre|
import ballerina/
public function main() {
service hello on new http:Listener(9090) {▼
}
}}
To execute the above program, place the source code in a <code>.bal</code> file and provide the path of the file to the <code>bal run</code> command.
resource function sayHello(http:Caller caller,▼
<syntaxhighlight lang="console">▼
▲ check caller->respond("Hello, World!");
$ ballerina run hello_world.bal▼
</syntaxhighlight>
The service version of the Hello World program:
{{pre|
import ballerina/http;
return "Hello World!";
}
}
}}
▲<syntaxhighlight lang="console">
▲$ ballerina run hello_world.bal
Services are executed in the same manner, except they don't terminate like regular programs do. Once the service is up and running, one can use an HTTP client to invoke the service. For example, the above service can be invoked using the following cURL command:
curl http://localhost:9090/hello/sayHello▼
▲Hello, World!
<syntaxhighlight lang="console">
Hello World!
</syntaxhighlight>
|