Concise reference for the public surface of DevOp.Toon.Client.
IToonClientThe primary interface. Inject this into application services via DI.
Task<T?> GetAsync<T>(string requestUri, CancellationToken cancellationToken = default);
Task<TResponse?> PostAsync<TRequest, TResponse>(string requestUri, TRequest request, CancellationToken cancellationToken = default);
Task<TResponse?> PutAsync<TRequest, TResponse>(string requestUri, TRequest request, CancellationToken cancellationToken = default);
Task<TResponse?> PatchAsync<TRequest, TResponse>(string requestUri, TRequest request, CancellationToken cancellationToken = default);
Task DeleteAsync(string requestUri, CancellationToken cancellationToken = default);
Task<T?> DeleteAsync<T>(string requestUri, CancellationToken cancellationToken = default);
All request methods that accept a body encode it as TOON using the configured EncodeOptions. All response methods deserialize based on the response Content-Type.
Returns null when the response body is empty or the server returns no content.
Throws ToonClientException on non-2xx responses, deserialization failures, or unsupported response content types.
AddToonClient(...)Registration extension on IServiceCollection:
services.AddToonClient();
services.AddToonClient(options => { ... });
IToonClient as a typed HttpClientIToonService via AddToon() if not already presentBaseAddress and Timeout to the underlying HttpClientHttpMessageHandler for automatic response decompression when EnableCompression is true (the default)ToonMediaType is not empty and Timeout (if set) is greater than zeroToonClientOptions| Property | Type | Default | Description |
|---|---|---|---|
BaseAddress |
Uri? |
null |
Base URI for all requests |
Timeout |
TimeSpan? |
null |
HTTP client timeout |
EnableCompression |
bool |
true |
Enables automatic GZip/Deflate/Brotli response decompression |
EncodeOptions |
ToonEncodeOptions? |
null |
Outbound TOON encoding settings |
DecodeOptions |
ToonDecodeOptions? |
null |
Inbound TOON decoding settings |
ResponseEncodeOverrides |
ToonResponseEncodeOverrideOptions? |
null |
Server-side response override headers |
JsonSerializerOptions |
JsonSerializerOptions |
Web defaults | JSON fallback deserialization settings |
ToonMediaType |
string |
application/toon |
Content-Type for outbound TOON requests |
ToonResponseEncodeOverrideOptionsAll properties are nullable. Only non-null properties produce an X-Toon-Option-* header.
| Property | Type |
|---|---|
Indent |
bool? |
Delimiter |
ToonDelimiter? |
KeyFolding |
ToonKeyFolding? |
FlattenDepth |
int? |
ObjectArrayLayout |
ToonObjectArrayLayout? |
IgnoreNullOrEmpty |
bool? |
ExcludeEmptyArrays |
bool? |
ToonClientExceptionThrown when:
Content-Type is not a recognized TOON or JSON media typeInherits from InvalidOperationException.
public string? Content { get; }
public string? ContentType { get; }
public HttpStatusCode? StatusCode { get; }
Content and ContentType are populated from the response body. StatusCode is set for both non-2xx responses and deserialization failures on successful responses. All three are null when the exception is created via the public constructor rather than thrown by ToonClient.
Decode<T>()public T? Decode<T>()
Deserializes Content into T using ContentType to select the decoder. Works for both TOON and JSON response bodies. Useful for reading structured error payloads such as ProblemDetails or custom error DTOs:
catch (ToonClientException ex)
{
var error = ex.Decode<ProblemDetails>();
}
Throws ToonClientException when ContentType is not a recognized TOON or JSON media type. Throws InvalidOperationException when called on an exception created via the public constructor (i.e. not thrown by ToonClient).
Prior to this version, non-2xx responses caused HttpClient to throw HttpRequestException. Non-2xx responses now throw ToonClientException consistently with all other failure modes. Catch sites that previously caught HttpRequestException from IToonClient calls must be updated to catch ToonClientException.