Skip to content

Instantly share code, notes, and snippets.

@dunithd
Created May 13, 2020 06:03
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 dunithd/3427d35926ed1daac5585ad5f9c4527e to your computer and use it in GitHub Desktop.
Save dunithd/3427d35926ed1daac5585ad5f9c4527e to your computer and use it in GitHub Desktop.
import ballerina/log;
import ballerina/http;
listener http:Listener todosListener = new(9090);
@http:ServiceConfig {
basePath: "/todos"
}
service TodoService on todosListener {
@http:ResourceConfig {
methods: ["GET"],
path: "/"
}
resource function getAll(http:Caller caller, http:Request request) {
//return some mock Todo objects as a JSON array
json todos = [
{
"id" : 1,
"name" : "Create the Todo Service",
"status" : "OPEN"
},
{
"id" : 2,
"name" : "Create an AKS Cluster",
"status" : "OPEN"
}
];
//respond to the caller
var responseResult = caller->respond(todos);
if (responseResult is error) {
log:printError("Error responding back to client.", responseResult);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment