Skip to content

Instantly share code, notes, and snippets.

@edgars
Created November 25, 2017 02:51
Show Gist options
  • Save edgars/98e7dd4787402487d50dff9bcf036975 to your computer and use it in GitHub Desktop.
Save edgars/98e7dd4787402487d50dff9bcf036975 to your computer and use it in GitHub Desktop.
package mine;
import ballerina.net.http;
@http:configuration {basePath:"/dolar"}
service<http> dolar {
endpoint
<http:HttpClient> httpConnector{
create http:HttpClient("http://api.bcb.gov.br/dados/serie/bcdata.sgs.1/dados/ultimos", {});}
http:HttpConnectorError err;
@http:resourceConfig {
methods:["GET"],
path:"/cotacao"
}
resource cotacao (http:Request req, http:Response res) {
endpoint<http:HttpClient> echoEndPoint{
create http:HttpClient("http://api.bcb.gov.br/dados/serie/bcdata.sgs.1/dados/ultimos", {});
}
http:Response clientResponse = {};
clientResponse, err = echoEndPoint.get("/", req);
println("Exemplo ##### ");
res.forward(clientResponse);
}
@http:resourceConfig {
methods:["GET"],
path:"/exemplo"
}
resource exemplo (http:Request req, http:Response res) {
endpoint<http:HttpClient> echoEndPoint{
create http:HttpClient("https://postman-echo.com", {});
}
http:Response clientResponse = {};
clientResponse, err = echoEndPoint.get("/get?test=123", req);
println("Exemplo ##### ");
res.forward(clientResponse);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment