//POST: add word book public static async Task AddWordBook(WordBook book) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:37533/"); await client.PostAsJsonAsync("api/wordbooks", book); } }
//PUT: update word book public static async Task UpdateWordBook(int id, WordBook book) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:37533/"); await client.PutAsJsonAsync("api/wordbooks/" + id, book); } }
//GET: get word book by id public static async Task <WordBook> GetWordBook(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/wordbooks/" + id); if (response.IsSuccessStatusCode) { WordBook book = await response.Content.ReadAsAsync <WordBook>(); return(book); } return(null); } }