Created
November 25, 2018 15:03
-
-
Save Manuri/a43e9148091423a848420d1832eccaf1 to your computer and use it in GitHub Desktop.
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/http; | |
import ballerina/io; | |
import wso2/mongodb; | |
import ballerinax/docker; | |
@docker:Expose{} | |
endpoint http:Listener Servicelistner { | |
port : 9090 | |
}; | |
endpoint mongodb:Client conn { | |
dbName: "test", | |
options : { url: "mongodb://test1:test1@cluster0-shard-00-00-gyqsg.mongodb.net:27017,cluster0-shard-00-01-gyqsg.mongodb.net:27017,cluster0-shard-00-02-gyqsg.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true"} | |
}; | |
@docker:Config { | |
registry: "ballerina.guides.io", | |
name: "ballerina_mongodb_service", | |
tag: "v1.0", | |
baseImage: "mongodb-ballerina" | |
} | |
service<http:Service> dummyService bind Servicelistner { | |
getData(endpoint caller, http:Request req) { | |
http:Response res = new; | |
var jsonRet = conn->find("Books", ()); | |
match jsonRet { | |
json j => { | |
res.setPayload(j); | |
} | |
error e => { | |
res.setPayload({ message: "Error occurred" }); | |
} | |
} | |
caller->respond(res) but { | |
error e => io:println("Error sending response") | |
}; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment