import ballerina/http;endpoint http:Listener helloWorldEP {
port:9095,
secureSocket: {
keyStore: {
filePath: "${ballerina.home}/bre/security/ballerinaKeystore.p12",
password: "ballerina"
}
}
};
@http:ServiceConfig {
endpoints:[helloWorldEP],
basePath:"/hello"
}
service<http:Service> helloWorld bind helloWorldEP {
@http:ResourceConfig {
methods:["GET"],
path:"/"
} sayHello (endpoint conn, http:Request req) {
http:Response res = new;
res.setStringPayload("Successful");
_ = conn -> respond(res);
}
}
HTTPS Server ConnectorThe HTTP Server Connector can be used to connect to and interact with a HTTP client. Https configurations can be given to server connector to expose a https connection. |
|
import ballerina/http;
|
|
endpoint http:Listener helloWorldEP {
port:9095,
secureSocket: {
keyStore: {
filePath: "${ballerina.home}/bre/security/ballerinaKeystore.p12",
password: "ballerina"
}
}
};
|
|
@http:ServiceConfig {
endpoints:[helloWorldEP],
basePath:"/hello"
}
service<http:Service> helloWorld bind helloWorldEP {
@http:ResourceConfig {
methods:["GET"],
path:"/"
}
|
Ballerina server connector can be used to connect to a https client. If client needs to verify server authenticity when establishing the connection, server needs to provide keyStoreFile, keyStorePassword and certificate password as given here. |
sayHello (endpoint conn, http:Request req) {
http:Response res = new;
res.setStringPayload("Successful");
_ = conn -> respond(res);
}
}
|
|
$ ballerina run https-server-connector.bal
ballerina: initiating service(s) in 'https-server-connector.bal'
ballerina: started HTTPS/WSS endpoint 0.0.0.0:9095
|
Run the service |
$ curl -k https://localhost:9095/hello
Successful
|
For the demonstration purpose curl -k command will be used to invoke the service. |