Skip to content

Instantly share code, notes, and snippets.

@caionitro
Created September 11, 2014 12:35
Show Gist options
  • Save caionitro/5421ec4db36bf61e634c to your computer and use it in GitHub Desktop.
Save caionitro/5421ec4db36bf61e634c to your computer and use it in GitHub Desktop.
API Transparência
var http = require('http');
var api = {
path : function(estado,cargo,partido,nome){
var api = '/api/v1/candidatos?estado='+estado+'&cargo='+cargo;
if(partido != null){
api += '&partido='+partido;
}
if(nome != null){
api += '&nome='+nome;
}
return api;
}
}
var info = {
host : 'api.transparencia.org.br',
port : 80,
path : api.path('PR',1),
method : 'GET',
headers: {'App-Token' : 'vRdqRoxdGSUk'}
};
var req = http.request(info, function(res) {
var retorno = '';
console.log("statusCode: ", res.statusCode);
res.on('data', function(ret) {
retorno += ret;
});
res.on('end',function(){
console.log(retorno);
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment