Skip to content

Instantly share code, notes, and snippets.

http:Response clientResponse = {};
clientResponse, err = httpConnector.post("/SigepMasterJPA/AtendeClienteService/AtendeCliente", req);
println("Convertendo XML para JSON ");
var xmlRetornavel, _ = <xml> clientResponse.getXmlPayload();
json respostaComoJSON = {"logradouro": xmlRetornavel.toJSON({})["soap:Envelope"]["soap:Body"]["ns2:consultaCEPResponse"]["return"]};
resource consultacep (http:Request req, http:Response res, string cep) {
xml soapRequest = xml `<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">
<soapenv:Header/>
<soapenv:Body>
<cli:consultaCEP>
<cep>{{cep}}</cep>
</cli:consultaCEP>
</soapenv:Body>
import ballerina.net.http;
@http:configuration {basePath:"/soap"}
service<http> cepservice {
endpoint
<http:HttpClient> httpConnector{
create http:HttpClient("https://apps.correios.com.br", {});
}
[54] → http http://localhost:9090/soap/cep/67133100
HTTP/1.1 200 OK
Content-Type: application/json
content-encoding: gzip
transfer-encoding: chunked
{
"logradouro": {
"bairro": "Cidade Nova",
"cep": "67133100",
import ballerina.net.http;
@http:configuration {basePath:"/soap"}
service<http> cepservice {
endpoint
<http:HttpClient> httpConnector{
create http:HttpClient("https://apps.correios.com.br", {});
}
package gateways;
import ballerina.net.http;
@http:configuration {basePath:"/soap"}
service<http> temperatureService {
endpoint
<http:HttpClient> httpConnector{
create http:HttpClient("http://www.webservicex.net/", {});
package gateways;
import ballerina.net.http;
@http:configuration {basePath:"/fipe"}
service<http> fipe {
endpoint
<http:HttpClient> httpConnector{
create http:HttpClient("https://fipe.parallelum.com.br/api/v1", {});
@http:resourceConfig {
methods:["GET"],
path:"/marcas/{tipoVeiculo}"
}
resource marcas (http:Request req, http:Response res, string tipoVeiculo) {
// https://fipe.parallelum.com.br/api/v1/{carros}/marcas {motos, caminhoes, carros}
http:Response clientResponse = {};
clientResponse, err = httpConnector.get("/"+ tipoVeiculo +"/marcas", {});
println("GET request: Marca Veiculos ");
res.forward(clientResponse);
package gateways;
import ballerina.net.http;
@http:configuration {basePath:"/fipe"}
service<http> fipe {
endpoint
<http:HttpClient> httpConnector{
create http:HttpClient("https://fipe.parallelum.com.br/api/v1", {});
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", {});}