Examples

Sample code:


    public class Candidato
    {
       public string id { get; set; }
       public string apelido { get; set; }
       public string nome { get; set; }
       public string numero { get; set; }
       public string titulo { get; set; }
       public string CPF { get; set; }
       public string matricula { get; set; }
       public string cargo { get; set; }
       public string estado { get; set; }
       public string partido { get; set; }
       public string idade { get; set; }
       public string instrucao { get; set; }
       public string ocupacao { get; set; }
       public string miniBio { get; set; }
       public string cargos { get; set; }
       public string previsao { get; set; }
       public string bancadas { get; set; }
       public string processos { get; set; }
       public string casaAtual { get; set; }
       public bool reeleicao { get; set; }
       public string foto { get; set; }
    }

Sample code:


    //Classe de suporte a consumo de HTTP namespace System.Net.Http
       HttpClient client = new HttpClient(); //Adicionando no Header o token e o media type JSON
       client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
       client.DefaultRequestHeaders.Add("App-Token", "tVKugWcoOJLt ");
    //Fazendo a requisição
       HttpResponseMessage response = client.GetAsync("http://api.transparencia.org.br/api/v1/candidatos?estado=sp&cargo=3").Result;
    //Conferindo código 200 de sucesso
    if (response.IsSuccessStatusCode)
    {
    //Parse de JSON para o objeto Candidato
       var listaDeCandidatos = response.Content.ReadAsAsync<IList<Candidato>>().Result;
    }
    else
       //Exibindo a exceção com o código Http respectivo.
       throw new Exception(string.Concat(response.StatusCode.ToString(), " - ", response.ReasonPhrase));

 

English