Skip to content

Instantly share code, notes, and snippets.

@edgars
Last active November 27, 2017 20:03
Show Gist options
  • Save edgars/b049232751fe64706ecb823efbaeec28 to your computer and use it in GitHub Desktop.
Save edgars/b049232751fe64706ecb823efbaeec28 to your computer and use it in GitHub Desktop.
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:HttpConnectorError err;
@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);
}
@http:resourceConfig {
methods:["GET"],
path:"/modelos/marca/{idMarca}"
}
resource modelos (http:Request req, http:Response res, string idMarca) {
http:Response clientResponse = {};
//sample: https://fipe.parallelum.com.br/api/v1/carros/marcas/59/modelos
clientResponse, err = httpConnector.get("/carros/marcas/" + idMarca + "/modelos", {});
println("GET request: Modelos Veiculos ");
res.forward(clientResponse);
}
@http:resourceConfig {
methods:["GET"],
path:"/anos/{idMarca}/{idModelo}"
}
resource anos (http:Request req, http:Response res, string idMarca, string idModelo) {
http:Response clientResponse = {};
// https://fipe.parallelum.com.br/api/v1/carros/marcas/59/modelos/5940/anos/2014-3
clientResponse, err = httpConnector.get("/carros/marcas/"+ idMarca +"/modelos/"+ idModelo+ "/anos" , {});
println("GET request: Anos dos Modelos Veiculos ");
res.forward(clientResponse);
}
@http:resourceConfig {
methods:["GET"],
path:"/precos/{idMarca}/{idModelo}/{idAno}"
}
resource preco (http:Request req, http:Response res, string idMarca, string idModelo, string idAno) {
http:Response clientResponse = {};
// https://fipe.parallelum.com.br/api/v1/carros/marcas/59/modelos/5940/anos/2014-3
clientResponse, err = httpConnector.get("/carros/marcas/"+ idMarca +"/modelos/"+ idModelo+ "/anos/"+idAno , {});
println("GET request: Anos dos Modelos Veiculos ");
res.forward(clientResponse);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment