Created
November 25, 2017 02:51
-
-
Save edgars/98e7dd4787402487d50dff9bcf036975 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
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