public static async Task <List <LivroModel> > Get() { LivroResponseGet responseGet = null; List <LivroModel> listaRetorno = null; var uri = new Uri(string.Format("{0}/Livros", urlBase)); using (var cliente = new HttpClient()) { HttpResponseMessage response = await cliente.GetAsync(uri); if (response.IsSuccessStatusCode) { // Retornou com sucesso var responseString = await response.Content.ReadAsStringAsync(); responseGet = JsonConvert.DeserializeObject <LivroResponseGet>(responseString); // Se não houve erro, extrai o resultado if (responseGet != null && responseGet.IndicadorErro == 0) { listaRetorno = responseGet.Livros; } } } return(listaRetorno); }
public static async Task <LivroModel> Get(int isbn) { LivroResponseGet responseGet = null; LivroModel livroResultado = null; var uri = new Uri(string.Format("{0}/Livros/{1}", urlBase, isbn)); using (var cliente = new HttpClient()) { //var data = JsonConvert.SerializeObject(request); //var content = new StringContent(data, Encoding.UTF8, "application/json"); HttpResponseMessage response = await cliente.GetAsync(uri); if (response.IsSuccessStatusCode) { // Retornou com sucesso var responseString = await response.Content.ReadAsStringAsync(); responseGet = JsonConvert.DeserializeObject <LivroResponseGet>(responseString); // Se não houve erro, extrai o resultado if (responseGet != null && responseGet.IndicadorErro == 0) { livroResultado = responseGet.Livros.FirstOrDefault(); } } } return(livroResultado); }