redb.Route.Templates 4.0.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package redb.Route.Templates --version 4.0.0
                    
NuGet\Install-Package redb.Route.Templates -Version 4.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="redb.Route.Templates" Version="4.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="redb.Route.Templates" Version="4.0.0" />
                    
Directory.Packages.props
<PackageReference Include="redb.Route.Templates" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add redb.Route.Templates --version 4.0.0
                    
#r "nuget: redb.Route.Templates, 4.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package redb.Route.Templates@4.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=redb.Route.Templates&version=4.0.0
                    
Install as a Cake Addin
#tool nuget:?package=redb.Route.Templates&version=4.0.0
                    
Install as a Cake Tool

redb.Route.Templates

Build a payload from a template instead of concatenating strings: the analog of WSO2 PayloadFactory and Camel's templating components, on Scriban. Templates live in files, embedded resources or inline; the result type is explicit so substituted values are escaped correctly for JSON or XML.

.SetBodyTemplate("Templates/order-confirm.json.sbn", MediaType.Json, a => a
    .Set("customer", "header.customerId")          // route expression language
    .Set("total", "header.amount * header.qty")
    .SetValue("channel", "email"))                 // constant
{
  "id": {{ headers.orderId }},
  "customer": "{{ args.customer }}",
  "items": [
    {{~ for i in body.items ~}}
    { "sku": "{{ i.sku }}", "qty": {{ i.qty }} }{{ if !for.last }},{{ end }}
    {{~ end ~}}
  ]
}

Rules

Rule Why
A string argument is a locator: a file path (relative to RouteTemplateOptions.BaseDirectory, default AppContext.BaseDirectory) or assembly:Name/Path/file.sbn. Inline text is TextSource.Inline("..."). A string never has to be guessed as "path or text" — the same rule the route expression language follows.
MediaType is mandatory: Json, Xml, Text. It decides escaping of substituted values ("/\/control characters for JSON; & < > " ' for XML) and the ContentType of the produced body. Template literals are never escaped — only values. {{ x \| raw }} writes a value verbatim.
Numbers and dates render culture-invariant; dates as ISO 8601. A payload must not depend on the server locale.
Compiled at route build, cached by source. A missing file or a syntax error fails Start() with the template name and (line,column).
Sandbox: no include, no context objects, .NET objects expose public properties and fields only. Templates are data, not code. A method call on a body object fails the render, and so does one inside expr(...) or an argument expression: those run under ExpressionSandbox, where the expression engine refuses reflection calls (its built-in helpers such as contains, substring, length keep working).

Data model in a template

Name What
body JSON text → object tree (body.order.id); XML text → navigable tree (body.order.item[0].sku, attributes and child elements as members, repeated children as arrays, element text under text); POCO → its public members with their C# names; dictionaries → members
headers.name, headers["Content-Type"] message headers
properties.name exchange properties
exception.message, .type, .stackTrace current exception or null
args.name named arguments of the step
expr("header.amount * header.qty") any route-language expression, evaluated by the same engine as ${...}
raw(value) / {{ value \| raw }} skip escaping for this value

Options

services.AddRouteTemplates(o => { o.BaseDirectory = "/etc/acme/templates"; o.Liquid = false; });
// or, without DI:
context.UseTemplates(o => o.StrictVariables = true);

Liquid = true switches to Scriban's Liquid-compatible syntax. StrictVariables makes a missing variable a render error instead of an empty string. LoopLimit (default 10 000) bounds loops.

Targets

SetBodyTemplate (body + ContentType), SetHeaderTemplate(name, ...), SetPropertyTemplate(key, ...).

XML form

The node's shape in the Route-XML catalog (docs/Route-XML/); the XML loader itself is not shipped yet, so today the node is declared through the DSL above.

<payload template="templates/order-confirm.json.sbn" mediaType="json">
  <arg name="customer" expr="header.customerId"/>
  <arg name="channel"  value="email"/>
</payload>

<payload mediaType="xml" target="header:X-Summary"><![CDATA[
  <summary items="{{ body.items | array.size }}"/>
]]></payload>
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.1 42 9/18/2026
4.0.0 80 9/11/2026