/// <summary> /// Execute a DELETE on a specified URL and get a strongly typed response using the specified client protocol. /// </summary> /// <typeparam name="ResponseType">The type returned by the endpoint.</typeparam> /// <param name="query">The query path appended to the base URL, e.g. "api/tables");</param> /// <returns></returns> public async Task <ResponseType> DeleteAsync <ResponseType>(string query, ClientProtol clientProtol = ClientProtol.Protobuf) { if (query.StartsWith("/")) { query = query.TrimStart('/'); } var mediaType = clientProtol == ClientProtol.Protobuf ? ProtobufMediaType : JsonMediaType; var client = GetHttpClient(); using (var request = new HttpRequestMessage(HttpMethod.Delete, _baseUrl + query)) { await AddAuthorizationBearerToken(request); client.DefaultRequestHeaders .Accept .Add(new MediaTypeWithQualityHeaderValue(mediaType)); var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); var result = clientProtol == ClientProtol.Protobuf ? ProtoBuf.Serializer.Deserialize <ResponseType>(await response.Content.ReadAsStreamAsync()) : JsonConvert.DeserializeObject <ResponseType>(await response.Content.ReadAsStringAsync()); return(result); } }
/// <summary> /// Execute a DELETE on a specified URL and get a strongly typed response using the specified client protocol. /// No response object. This endpoint has a controller that returns void or Task. /// </summary> /// <param name="query">The query path appended to the base URL, e.g. "api/tables");</param> /// <returns></returns> public async Task DeleteAsync(string query, ClientProtol clientProtol = ClientProtol.Protobuf) { if (query.StartsWith("/")) { query = query.TrimStart('/'); } var mediaType = clientProtol == ClientProtol.Protobuf ? ProtobufMediaType : JsonMediaType; var client = GetHttpClient(); using (var request = new HttpRequestMessage(HttpMethod.Delete, _baseUrl + query)) { await AddAuthorizationBearerToken(request); client.DefaultRequestHeaders .Accept .Add(new MediaTypeWithQualityHeaderValue(mediaType)); var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); } }
/// <summary> /// Execute a PUT on specified URL with data of RequestType to get a strongly typed response using the specified client protocol. /// No response object. This endpoint has a controller that returns void or Task. /// </summary> /// <typeparam name="RequestType">The type of the data being sent via the request to the endpoint.</typeparam> /// <param name="query">The query path appended to the base URL, e.g. "api/tables");</param> /// <param name="data">The data being sent via PUT to the endpoint.</param> /// <returns></returns> public async Task PutAsync <RequestType>(string query, RequestType data, ClientProtol clientProtol = ClientProtol.Protobuf) { if (query.StartsWith("/")) { query = query.TrimStart('/'); } var mediaType = clientProtol == ClientProtol.Protobuf ? ProtobufMediaType : JsonMediaType; var client = GetHttpClient(); using (var request = new HttpRequestMessage(HttpMethod.Put, _baseUrl + query)) using (var ms = new MemoryStream()) { await AddAuthorizationBearerToken(request); client.DefaultRequestHeaders .Accept .Add(new MediaTypeWithQualityHeaderValue(mediaType)); ProtoBuf.Serializer.Serialize <RequestType>(ms, data); request.Content = new ByteArrayContent(ms.ToArray()); var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); } }