Created
February 24, 2018 11:42
-
-
Save pubudu91/870e477136c2dae9535daab7e48a6c14 to your computer and use it in GitHub Desktop.
Use of config API for configuring HTTP services dynamically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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