EasyAF_Http_SystemTextJson_HttpResponseMessageExtensions

Provides extension methods for HttpResponseMessage to deserialize JSON responses using System.Text.Json. Includes support for both success and error response handling with configurable serializer options.

Syntax

public static class EasyAF_Http_SystemTextJson_HttpResponseMessageExtensions

Inheritance

Methods

DeserializeResponseAsync<T>

public static Task<(T Response, string ErrorContent)> DeserializeResponseAsync<T>(this HttpResponseMessage message, JsonSerializerOptions settings)
Deserializes the HTTP response message content to the specified type using System.Text.Json with custom options. 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<T>

public static Task<(T Response, string ErrorContent)> DeserializeResponseAsync<T>(this HttpResponseMessage message)
Deserializes the HTTP response message content to the specified type using System.Text.Json with default options. 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, JsonSerializerOptions settings)
Deserializes the HTTP response message content to strongly-typed response and error objects using System.Text.Json with custom options. 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.

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 System.Text.Json with default options. 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.