Skip to content

Instantly share code, notes, and snippets.

@daneshk
Created February 5, 2018 12:56
Show Gist options
  • Save daneshk/eeb65ab70559eba6b81cc56199722e04 to your computer and use it in GitHub Desktop.
Save daneshk/eeb65ab70559eba6b81cc56199722e04 to your computer and use it in GitHub Desktop.
package org.ballerinalang.net.grpc.stockquote;
import ballerina.net.grpc;
service<grpc> StockQuoteService {
resource getQuote (StockRequest req, StockQuote res) {
println("Getting stock details for symbol: " + req.name);
res.symbol = "IBM";
res.name = "International Business Machines";
res.last = 149.52;
res.low = 150.70;
res.high = 149.18;
println(res);
//res = {symbol:"IBM", name:"International Business Machines", last:149.52, low:150.70, high:149.18};
}
resource addStock (StockQuote req, Void res) {
println("Symbol: " + req.symbol);
println("Name: " + req.name);
println("Last: " + req.last);
println("Low: " + req.low);
println("High: " + req.high);
}
resource getQuotes(Void req, StockQuotes quotes) {
StockQuote res = {};
res.symbol = "WSO2";
res.name = "WSO2 Inc.";
res.last = 14;
res.low = 15;
res.high = 16;
StockQuote res1 = {};
res1.symbol = "Google";
res1.name = "Google Inc.";
res1.last = 100;
res1.low = 101;
res1.high = 102;
quotes.stock = [res,res1];
println(quotes);
}
resource getNames(Void req, StockNames quotes) {
string[] names = ["WSO2", "Google"];
println(names);
quotes.names = names;
}
}
struct StockQuote {
string symbol;
string name;
float last;
float low;
float high;
}
struct StockRequest {
@grpc:protobuf {fieldType:"string",
index:1,
name:"name"}
string name;
}
struct StockQuotes {
StockQuote[] stock;
}
struct StockNames {
string[] names;
}
struct Void {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment