Skip to main content

HttpClientExtensions

A static class in Alta.Api.DataTransferModels, Alta.Api.DataTransferModels.Extensions.

HttpClient helpers for the API client: JSON post, put, patch and delete, with debug logging of requests and responses.

Fields​

1 private and internal field
MemberWhat it is
private static readonly Logger loggerClass logger.

Methods​

MemberWhat it is
static async Task<HttpResponseMessage> DeleteAsync(HttpClient client, string requestUri, HttpContent content)Sends a DELETE with a body, which plain HttpClient doesn't offer.
static Task<HttpResponseMessage> DeleteJsonAsync<T>(HttpClient client, string uri, T content)Sends a DELETE with the object as a JSON body.
static async Task<HttpResponseMessage> PatchAsync(HttpClient client, string requestUri, HttpContent content)Sends a PATCH request with the given content.
static Task<HttpResponseMessage> PatchJsonAsync<T>(HttpClient client, string uri, T content)Sends a PATCH with the object as a JSON body.
static async Task<HttpResponseMessage> PostAsync<T>(HttpClient client, string uri)Posts with no body and logs the request and response.
static async Task<HttpResponseMessage> PostJsonAsync<T>(HttpClient client, string uri, T content, Action<HttpClientExtensions.JsonContent> modifyContent = null)Posts the object as JSON, with an optional hook to change the content first, and logs the request and response.
static Task<HttpResponseMessage> PutJsonAsync<T>(HttpClient client, string uri, T content)Sends a PUT with the object as a JSON body.
2 private and internal methods
MemberWhat it is
private static async Task LogApiRequest(string uri, HttpClientExtensions.JsonContent content)Writes the request URI, and the JSON body if there is one, to the debug log.
private static void LogApiRequest(string uri)Writes the request URI, and the JSON body if there is one, to the debug log.