public async Task <Todo> GetAsync(int id) { await PrepareAuthenticatedClient(); var response = await _httpClient.GetAsync($"{ _TodoListBaseAddress}/api/todolist/{id}"); if (response.StatusCode == HttpStatusCode.OK) { var content = await response.Content.ReadAsStringAsync(); Todo todo = JsonConvert.DeserializeObject <Todo>(content); return(todo); } throw new HttpRequestException($"Invalid status code in the HttpResponseMessage: {response.StatusCode}."); }
public async Task <Todo> EditAsync(Todo todo) { await PrepareAuthenticatedClient(); var jsonRequest = JsonConvert.SerializeObject(todo); var jsoncontent = new StringContent(jsonRequest, Encoding.UTF8, "application/json-patch+json"); var response = await _httpClient.PatchAsync($"{ _TodoListBaseAddress}/api/todolist/{todo.Id}", jsoncontent); if (response.StatusCode == HttpStatusCode.OK) { var content = await response.Content.ReadAsStringAsync(); todo = JsonConvert.DeserializeObject <Todo>(content); return(todo); } throw new HttpRequestException($"Invalid status code in the HttpResponseMessage: {response.StatusCode}."); }