Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Created December 16, 2018 13:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save icebeam7/1c0e324cf3b84eb7f6aa7f1712dcb90e to your computer and use it in GitHub Desktop.
VideoGameMusicApp: ServicioCanciones.cs
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Newtonsoft.Json;
using VideoGameMusicApp.Helpers;
using VideoGameMusicApp.Models;
namespace VideoGameMusicApp.Services
{
public static class ServicioCanciones
{
private static readonly HttpClient cliente = CrearHttpClient();
private static HttpClient CrearHttpClient()
{
var httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(Constantes.AzureFunctionsEndpoint);
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
return httpClient;
}
public async static Task<List<Cancion>> ObtenerCanciones()
{
try
{
var response = await cliente.GetAsync(Constantes.ObtenerCancionesUrl);
if (response.IsSuccessStatusCode)
{
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<Cancion>>(json);
}
}
catch (Exception ex)
{
}
return new List<Cancion>();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment