Skip to content

Instantly share code, notes, and snippets.

@almirvuk
Last active February 24, 2017 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almirvuk/d7e260a790716b80d6835aad50734849 to your computer and use it in GitHub Desktop.
Save almirvuk/d7e260a790716b80d6835aad50734849 to your computer and use it in GitHub Desktop.
using CarsExample.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using Newtonsoft.Json;
namespace CarsExample.Utils {
public class MyHTTP {
// Get new data rows
public static async Task GetAllNewsAsync(Action<IEnumerable<Car>> action) {
HttpClient httpClient = new HttpClient();
HttpResponseMessage response = await httpClient.GetAsync("https://api.myjson.com/bins/jly7p");
if (response.StatusCode == System.Net.HttpStatusCode.OK) {
var list = JsonConvert.DeserializeObject<IEnumerable<Car>>(await response.Content.ReadAsStringAsync());
action(list);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment