Created
December 16, 2018 13:38
-
-
Save icebeam7/1c0e324cf3b84eb7f6aa7f1712dcb90e to your computer and use it in GitHub Desktop.
VideoGameMusicApp: ServicioCanciones.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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