redb.Route.Templates
4.7.2
Prefix Reserved
dotnet add package redb.Route.Templates --version 4.7.2
NuGet\Install-Package redb.Route.Templates -Version 4.7.2
<PackageReference Include="redb.Route.Templates" Version="4.7.2" />
<PackageVersion Include="redb.Route.Templates" Version="4.7.2" />
<PackageReference Include="redb.Route.Templates" />
paket add redb.Route.Templates --version 4.7.2
#r "nuget: redb.Route.Templates, 4.7.2"
#:package redb.Route.Templates@4.7.2
#addin nuget:?package=redb.Route.Templates&version=4.7.2
#tool nuget:?package=redb.Route.Templates&version=4.7.2
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 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. |
A relative path is looked up by the context's IRouteResourceResolver first, then by RouteTemplateOptions.BaseDirectory (default AppContext.BaseDirectory). A miss names both places. |
One lookup order for the whole framework: the same one validateXsd, xslt and the XML context files use. A route inside a .tpkg keeps its template in resources/, which only the package resolver knows about — the base directory stays the worker's. |
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 same node in an XML route (redb.Route.Xml):
<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 | Versions 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. |
-
net10.0
- JsonPath.Net (>= 2.2.0)
- JsonSchema.Net (>= 7.3.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.13)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Options (>= 10.0.13)
- redb.Route (>= 4.7.2)
- redb.Route.Xml (>= 4.7.2)
- Scriban (>= 7.5.1)
-
net8.0
- JsonPath.Net (>= 2.2.0)
- JsonSchema.Net (>= 7.3.4)
- Microsoft.Bcl.AsyncInterfaces (>= 10.0.13)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.13)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Options (>= 10.0.13)
- redb.Route (>= 4.7.2)
- redb.Route.Xml (>= 4.7.2)
- Scriban (>= 7.5.1)
-
net9.0
- JsonPath.Net (>= 2.2.0)
- JsonSchema.Net (>= 7.3.4)
- Microsoft.Bcl.AsyncInterfaces (>= 10.0.13)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.13)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Options (>= 10.0.13)
- redb.Route (>= 4.7.2)
- redb.Route.Xml (>= 4.7.2)
- Scriban (>= 7.5.1)
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.7.2 | 32 | 11/13/2026 |
| 4.7.1 | 48 | 11/11/2026 |
| 4.7.0 | 95 | 11/7/2026 |
| 4.6.2 | 95 | 11/5/2026 |
| 4.6.1 | 99 | 11/4/2026 |
| 4.6.0 | 84 | 11/3/2026 |
| 4.5.1 | 107 | 10/30/2026 |
| 4.5.0 | 100 | 10/29/2026 |
| 4.4.2 | 103 | 10/23/2026 |
| 4.4.1 | 109 | 10/21/2026 |
| 4.3.0 | 112 | 10/14/2026 |
| 4.2.3 | 98 | 10/8/2026 |
| 4.2.2 | 105 | 10/5/2026 |
| 4.2.0 | 119 | 9/30/2026 |
| 4.1.1 | 113 | 9/25/2026 |
| 4.1.0 | 103 | 9/21/2026 |
| 4.0.1 | 117 | 9/18/2026 |
| 4.0.0 | 115 | 9/11/2026 |