//POST: add word card public static async Task AddWordCard(WordCard card) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:37533/"); await client.PostAsJsonAsync("api/wordcards", card); } }
//PUT: update word card public static async Task UpdateWordCard(int id, WordCard card) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:37533/"); await client.PutAsJsonAsync("api/wordcards/" + id, card); } }
//GET: get word card by id public static async Task <WordCard> GetWordCard(int id) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:37533/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.GetAsync("api/wordcards/" + id); if (response.IsSuccessStatusCode) { WordCard card = await response.Content.ReadAsAsync <WordCard>(); return(card); } else { return(null); } } }