Ballerina (programming language): Difference between revisions

Content deleted Content added
PubuduF (talk | contribs)
Removing gRPC example since a concise working example cannot be written for it
Tag: section blanking
PubuduF (talk | contribs)
Add GraphQL example
Line 109:
$ curl http://localhost:9090/factorial -d 5
120
</syntaxhighlight>
 
=== GraphQL API ===
<syntaxhighlight>
import ballerina/graphql;
 
service /stocks on new graphql:Listener(4000) {
resource function get quote() returns StockQuote {
return {
ticker: "EXPO",
price: 287.5,
open: 285,
prevClose: 285.5,
low: 276.25,
high: 297
};
}
}
 
type StockQuote record {|
string ticker;
float price;
float open;
float prevClose;
float low;
float high;
|};
</syntaxhighlight>
 
<syntaxhighlight lang="console">
$ curl -H "Content-type: application/json" -d '{"query": "{ quote { ticker, price } }" }' 'http://localhost:4000/stocks'
{"data":{"quote":{"ticker":"EXPO", "price":287.5}}}
</syntaxhighlight>