EasyAF_Http_NewtonsoftJson_HttpResponseMessageExtensions

Provides extension methods for HttpResponseMessage to deserialize JSON responses using Newtonsoft.Json. Includes support for both success and error response handling with automatic contract resolver configuration.

Syntax

public static class EasyAF_Http_NewtonsoftJson_HttpResponseMessageExtensions

Inheritance

Methods

DeserializeResponseAsync<T>

public static Task<(T Response, string ErrorContent)> DeserializeResponseAsync<T>(this HttpResponseMessage message, JsonSerializerSettings settings)
Deserializes the HTTP response message content to the specified type using Newtonsoft.Json with custom settings. Automatically configures SystemTextJsonContractResolver if not already set. Returns either the deserialized response or error content as a string.

Parameters

  • message HttpResponseMessage: The HTTP response message to deserialize.
  • settings JsonSerializerSettings: The JSON serializer settings to use for deserialization.

Returns

Task<(T Response, string ErrorContent)> A tuple containing either the deserialized response object or error content string.

DeserializeResponseAsync<T>

public static Task<(T Response, string ErrorContent)> DeserializeResponseAsync<T>(this HttpResponseMessage message)
Deserializes the HTTP response message content to the specified type using Newtonsoft.Json with default settings. Returns either the deserialized response or error content as a string.

Parameters

Returns

Task<(T Response, string ErrorContent)> A tuple containing either the deserialized response object or error content string.

DeserializeResponseAsync<TResponse, TError>

public static Task<(TResponse Response, TError ErrorContent)> DeserializeResponseAsync<TResponse, TError>(this HttpResponseMessage message, JsonSerializerSettings settings)
Deserializes the HTTP response message content to strongly-typed response and error objects using Newtonsoft.Json with custom settings. Automatically configures SystemTextJsonContractResolver if not already set. Provides type-safe error handling by deserializing error responses to a specific error type.

Parameters

  • message HttpResponseMessage: The HTTP response message to deserialize.
  • settings JsonSerializerSettings: The JSON serializer settings to use for deserialization.

Returns

Task<(TResponse Response, TError ErrorContent)> A tuple containing either the deserialized response object or deserialized error object.

DeserializeResponseAsync<TResponse, TError>

public static Task<(TResponse Response, TError ErrorContent)> DeserializeResponseAsync<TResponse, TError>(this HttpResponseMessage message)
Deserializes the HTTP response message content to strongly-typed response and error objects using Newtonsoft.Json with default settings. Provides type-safe error handling by deserializing error responses to a specific error type.

Parameters

Returns

Task<(TResponse Response, TError ErrorContent)> A tuple containing either the deserialized response object or deserialized error object.