Ejemplo n.º 1
0
        public static async Task <List <Alumno> > Consultar(Dictionary <string, string> filtros = null)
        {
            var endpoint = new UriBuilder(Endpoint);

            if (filtros != null)
            {
                var endpointParams = new QueryParameters(endpoint.Query);
                endpointParams.Append(filtros);
                endpoint.Query = endpointParams.ToString();
            }

            var client   = new HttpClient();
            var response = await client.GetAsync(endpoint.Uri);

            var content = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                return(JsonConvert.DeserializeObject <List <Alumno> >(content));
            }
            else
            {
                var result = JsonConvert.DeserializeObject <RestError>(content);
                throw new Exception(result.Error);
            }
        }