/// <summary> /// Sends an HTTP DELETE request and returns the reponse as a JSON string /// </summary> /// <param name="resource">The resource identifier for the resource to be called (after /api/<version></version>/)</param> /// <returns>The response content in the form of a JSON string</returns> /// <exception cref="AggregateException">Thrown when the API response status code is not success or when the API call times out</exception> /// <exception cref="InvalidOperationException">Thrown when the call is made in batch mode but the current batch has no more room for additional API calls</exception> public static async Task <string> SendDeleteRequestAsync(string resource) { using (var client = new HttpClient()) { // Prepare the DELETE request ConfigureHttpClient(client); var uri = BuildFullResourceString(resource); // If batch mode is enabled then add the request to the current batch of requests to send later on if (BatchApiRequest.IsBatchApiModeEnabled() == true) { BatchApiRequest.AddApiRequest(new BatchApiRequest(uri, "DELETE")); return(String.Empty); } // Otherwise, send the DELETE request else { return(await RunWithRetries(() => client.DeleteAsync(uri))); } } }
/// <summary> /// Sends an HTTP PUT request and returns the reponse as a JSON string /// </summary> /// <param name="resource">The resource identifier for the resource to be called (after /api/<version>/)</param> /// <param name="content">The object to be sent with the PUT request. Will be converted to JSON in this function</param> /// <returns>The response content in the form of a JSON string</returns> /// <exception cref="AggregateException">Thrown when the API response status code is not success or when the API call times out</exception> /// <exception cref="InvalidOperationException">Thrown when making a Batch API Request that has already reached the maxmimum API calls per batch request</exception> public static async Task <string> SendPutRequestAsync(string resource, object content) { using (var client = new HttpClient()) { // Prepare the PUT request ConfigureHttpClient(client); var uri = BuildFullResourceString(resource); var httpContent = ConvertObjectToJsonHttpContent(content); // If batch mode is enabled then add the request to the current batch of requests to send later on if (BatchApiRequest.IsBatchApiModeEnabled() == true) { BatchApiRequest.AddApiRequest(new BatchApiRequest(uri, "PUT", content)); return(String.Empty); } // Otherwise, send the PUT request else { return(await RunWithRetries(() => client.PutAsync(uri, httpContent))); } } }
/// <summary> /// Sends an HTTP GET request and returns the reponse as a JSON string /// </summary> /// <param name="resource">The resource identifier for the resource to be called (after /api/<version>/)</param> /// <param name="queryParameters">The query parameters to use with the API call</param> /// <returns>The response content in the form of a JSON string</returns> /// <exception cref="AggregateException">Thrown when the API response status code is not success or when the API call times out</exception> /// <exception cref="InvalidOperationException">Thrown when making a Batch API Request that has already reached the maxmimum API calls per batch request</exception> public static async Task <string> SendGetRequestAsync(string resource, Dictionary <string, object> queryParameters) { using (var client = new HttpClient()) { // Prepare the GET request ConfigureHttpClient(client); var queryString = ConvertQueryParametersToQueryString(queryParameters); var uri = String.Format("{0}{1}", BuildFullResourceString(resource), queryString); // If batch mode is enabled then add the request to the current batch of requests to send later on if (BatchApiRequest.IsBatchApiModeEnabled() == true) { BatchApiRequest.AddApiRequest(new BatchApiRequest(uri, "GET")); return(String.Empty); } // Otherwise, send the GET request else { return(await RunWithRetries(() => client.GetAsync(uri))); } } }