ToonClientOptions is the single configuration point for DevOp.Toon.Client. Pass a configuration callback to AddToonClient(...) to set options at registration time.
builder.Services.AddToonClient(options =>
{
// configure here
});
Options are cloned on registration so external mutations after AddToonClient(...) returns do not affect the running client.
Version scope: Core 0.2.0, runtime 0.3.0, API 0.2.0, and Client 0.2.0.
Encoding defaults to official 4.4. Supply ToonEncodeOptions.ProtocolVersion with a concrete ToonProtocolVersion: V3_0, V4_0 through V4_4, CustomLegacy, or CustomV4_4. Decoding defaults to Auto; ambiguous version-dependent input needs an explicit ToonDecodeOptions.ProtocolVersion. Auto cannot be used for encoding or as a transport version.
Select CustomLegacy to retain the earlier custom wire profile. CustomV4_4 combines nested header groups with row/keyed spills. Custom profiles require compatible readers at both ends and default IgnoreNullOrEmpty and ExcludeEmptyArrays to true. Official profiles default both to false. Set both explicitly false when preserving null, empty-string, and empty-array distinctions matters. Explicit option overrides remain effective when changing versions. Columnar requires a custom protocol selection.
Encoder options and runtime DI encoding default to one-space indentation; decoder options default to two spaces. With explicit decode options, match the producer’s indentation or detect options using the supplied version hint. API registration aligns both widths at two spaces. Byte sequences default to Base64 strings; numeric-array output is an explicit policy choice.
Request X-Toon-Version labels the request body. Request X-Toon-Option-ProtocolVersion independently selects the response format. Response X-Toon-Version labels the actual TOON response. Concrete wire names are 3.0, 4.0 through 4.4, custom-legacy, and custom-4.4.
API 0.2.0 validates version headers and supplied X-Toon-Option-* headers before model binding/body consumption. Malformed, multiple, or conflicting body versions return 400; well-formed unsupported body versions return 415. Malformed response-version requests return 400; well-formed unsupported response versions return 406. Version validation errors use application/problem+json.
X-Toon-Option-Indent takes an integer width from 1 through 16; booleans and out-of-range widths return 400. This HTTP input limit is separate from trusted direct runtime configuration. API indentation defaults to two spaces when no override is supplied.
Client 0.2.0 changes ToonResponseEncodeOverrideOptions.Indent from bool? to int?. Use Indent = 2, or null to omit the override. EncodeOptions.ProtocolVersion controls outbound request bodies; ResponseEncodeOverrides.ProtocolVersion controls response selection. Invalid, unsupported, multiple, or conflicting response-version hints produce ToonClientException. An explicit decoder setting must agree with the response header. Without a header, configured decode options apply, defaulting to Auto.
BaseAddressoptions.BaseAddress = new Uri("https://api.example.com/");
Base URI applied to the underlying HttpClient. All relative request URIs resolve against this.
Timeoutoptions.Timeout = TimeSpan.FromSeconds(30);
HTTP client timeout. Must be greater than zero if set.
EnableCompressionoptions.EnableCompression = true; // default
When true (the default), the registered HttpClient automatically decompresses GZip and Deflate responses. On .NET 5 and later, Brotli is also included. This also causes the client to send the appropriate Accept-Encoding request headers automatically — no manual header configuration is needed.
Set to false to opt out entirely, for example when an intermediary proxy handles decompression.
EncodeOptionsoptions.EncodeOptions = new ToonEncodeOptions
{
ProtocolVersion = ToonProtocolVersion.CustomV4_4,
ObjectArrayLayout = ToonObjectArrayLayout.Columnar,
KeyFolding = ToonKeyFolding.Off
};
Controls how outbound request bodies are TOON-encoded. The default options select official 4.4, one-space indentation, Base64 byte sequences, and both omission options false. If explicitly set to null, ToonEncoder.DefaultOptions applies.
DecodeOptionsoptions.DecodeOptions = new ToonDecodeOptions
{
Strict = true
};
Controls how inbound TOON response bodies are decoded.
ResponseEncodeOverridesoptions.ResponseEncodeOverrides = new ToonResponseEncodeOverrideOptions
{
ProtocolVersion = ToonProtocolVersion.CustomV4_4,
ObjectArrayLayout = ToonObjectArrayLayout.Columnar,
KeyFolding = ToonKeyFolding.Off,
Indent = 2,
IgnoreNullOrEmpty = true,
ExcludeEmptyArrays = true
};
Sends X-Toon-Option-* headers on every request to instruct the server how to shape its TOON response. Only non-null properties produce a header.
Supported override properties:
ProtocolVersionIndentDelimiterKeyFoldingFlattenDepthObjectArrayLayoutIgnoreNullOrEmptyExcludeEmptyArraysThis works with any server running DevOp.Toon.API.
JsonSerializerOptionsoptions.JsonSerializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web);
Used when the response content type is JSON rather than TOON. Defaults to JsonSerializerDefaults.Web (camelCase, case-insensitive).
ToonMediaTypeoptions.ToonMediaType = ToonMediaTypes.Application; // "application/toon"
The media type sent as the request body Content-Type. Defaults to application/toon. Set to text/toon if the server requires it.
ToonClient accepts an optional ILogger<ToonClient> that is resolved automatically from the DI container when using AddToonClient(...). No additional configuration is needed — standard ILoggingBuilder setup (e.g. builder.Logging) controls the output.
Log levels used:
The client sends an Accept header with the following priority chain on every request:
| Media type | Priority |
|---|---|
application/toon |
1.0 |
text/toon |
0.9 |
application/json |
0.8 |
Responses are deserialized based on the actual response Content-Type:
IToonService decodeSystem.Text.Json deserializeToonClientExceptionNon-2xx responses throw ToonClientException regardless of content type.
Source usage reference: DevOp.Toon.Client README.