//DELETE public async void deleteTask(Entity.Task myTask) { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(REST_BASE_URL); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Delete, REST_PATH + myTask.id); await client.SendAsync(request); } }
//PUT public async void updateTask(Entity.Task myTask) { myTask.createdAt = DateTime.Now.ToString("dd'-'MM'-'yyyy HH:mm:ss"); using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(REST_BASE_URL); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, REST_PATH + myTask.id); request.Content = new StringContent(myTask.SerializeToDoTask(), Encoding.UTF8, "application/json"); await client.SendAsync(request); } }
//POST public async void postTask(Entity.Task myTask) { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(REST_BASE_URL); client.DefaultRequestHeaders .Accept .Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, REST_PATH); request.Content = new StringContent(myTask.SerializeToDoTask(), Encoding.UTF8, "application/json"); await client.SendAsync(request); } }