Skip to content

Instantly share code, notes, and snippets.

@pubudu91
Created February 24, 2018 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pubudu91/870e477136c2dae9535daab7e48a6c14 to your computer and use it in GitHub Desktop.
Save pubudu91/870e477136c2dae9535daab7e48a6c14 to your computer and use it in GitHub Desktop.
Use of config API for configuring HTTP services dynamically
import ballerina.net.http;
import ballerina.config;
const int httpPort = initPort();
@http:configuration {port:httpPort}
service<http> echo {
@http:resourceConfig {
path:"/"
}
resource echoResource (http:Connection conn, http:InRequest req) {
http:OutResponse res = {};
res.setStringPayload("Resource invoked");
_ = conn.respond(res);
}
}
function initPort() (int) {
string portStr = config:getGlobalValue("http.port");
int port;
port, _ = <int>portStr;
return port;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment