This page is the shortest path to enabling TOON in an ASP.NET Core MVC app.
dotnet add package DevOp.Toon.API
using DevOp.Toon.API;
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddControllers()
.AddToon();
If the request asks for application/toon or text/toon, the MVC formatter pipeline can serialize the response using TOON automatically.
Controllers can also receive TOON payloads through normal model binding when the request content type is TOON.
AddToon() starts from the API transport profile used by this package:
options.Encode.IgnoreNullOrEmpty = true;options.Encode.Delimiter = ToonDelimiter.COMMA;options.Encode.Indent = 1;options.Encode.ExcludeEmptyArrays = true;options.Encode.KeyFolding = ToonKeyFolding.Off;options.Encode.ObjectArrayLayout = ToonObjectArrayLayout.Columnar;options.Encode.ByteArrayFormat = ToonByteArrayFormat.Base64String;Override only the values your API needs to change:
builder.Services
.AddControllers()
.AddToon(options =>
{
options.Encode.Indent = 2;
options.Encode.IgnoreNullOrEmpty = false;
options.Encode.ByteArrayFormat = ToonByteArrayFormat.NumericArray;
});
ByteArrayFormat controls how byte[], List<byte>, and IEnumerable<byte> are written. options.Encode.ByteArrayFormat = ToonByteArrayFormat.Base64String; is the default compact transport form. Use NumericArray when a client needs JSON-like numeric byte arrays instead.
Help along with development costs and support us here