Bundle: redb-route / demo/EchoWorkerDemo (demo.EchoWorkerDemo.txt), 7 files
Snapshot: development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Index: https://redbase.app/src/dev-2026-12-06/redb-route/_index.txt
====
Path: redb-route/demo/EchoWorkerDemo/EchoModule/EchoModule.config.json
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/demo/EchoWorkerDemo/EchoModule/EchoModule.config.json
----
{
"ContextName": "echo",
"AutoStart": true
}
Path: redb-route/demo/EchoWorkerDemo/EchoModule/EchoModule.csproj
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/demo/EchoWorkerDemo/EchoModule/EchoModule.csproj
----
net10.0
enable
enable
EchoModule
false
EchoModule
<_TpkgStaging>$(IntermediateOutputPath)tpkg
<_TpkgFile>$(MSBuildThisFileDirectory)output\$(TsakModuleName).tpkg
Path: redb-route/demo/EchoWorkerDemo/EchoModule/InitRoute.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/demo/EchoWorkerDemo/EchoModule/InitRoute.cs
----
using System.Text.Json;
using redb.Core; // IRedbService, Query, SaveAsync, SyncSchemeAsync
using redb.Core.Attributes; // RedbScheme
using redb.Core.Models.Entities; // RedbObject
using redb.Route.Abstractions; // IRouteContext, IExchange
using redb.Route.Core; // RouteContext
using redb.Route.Http; // HttpComponent, SharedHttpServerManager
using redb.Route.RedbCore.Extensions; // ProcessWithRedb, GetRedbService
namespace EchoModule;
///
/// Tsak module entry point.
///
/// The worker discovers it by convention — a public static class named
/// InitRoute with a public static main(IRouteContext) — and calls it
/// once when the module loads. The debug host (EchoWorker/Program.cs) calls the very
/// same method, so the route code below lives in exactly one place.
///
///
/// Two minimal endpoints on the shared HTTP server (port 5099), backed by redb/SQLite:
///
/// POST /api/notes body {"tag":"work","text":"hello"} → save one note
/// GET /api/notes?tag=work → list notes with that tag
///
///
///
public static class InitRoute
{
private static readonly JsonSerializerOptions Json = new() { PropertyNameCaseInsensitive = true };
public static IRouteContext main(IRouteContext context)
{
// redb schema for Note. Idempotent — safe to call every load. The worker
// (or the debug host) has already brought redb + SQLite up by now.
context.GetRedbService().SyncSchemeAsync().GetAwaiter().GetResult();
// One shared HTTP server; both routes below bind to it.
context.AddComponent(new HttpComponent { ServerManager = new SharedHttpServerManager() });
((RouteContext)context).AddRoutes(r =>
{
// ── POST /api/notes — save one note ────────────────────────────────
r.From("http:0.0.0.0:5099/api/notes?inOut=true&methods=POST")
.RouteId("notes-post")
.ConvertBody() // HTTP body → string (JSON)
.ProcessWithRedb(async (db, ex, ct) =>
{
var note = JsonSerializer.Deserialize(ex.In.Body?.ToString() ?? "{}", Json) ?? new Note();
var obj = new RedbObject { name = $"note:{note.Tag}", Props = note };
await db.SaveAsync(obj); // one insert into redb (SQLite)
Reply(ex, new { saved = true, id = obj.id });
}).Log("Save ${body}");
// ── GET /api/notes?tag=work — list by tag ──────────────────────────
r.From("http:0.0.0.0:5099/api/notes?inOut=true&methods=GET")
.RouteId("notes-get")
.ProcessWithRedb(async (db, ex, ct) =>
{
// ?tag=... arrives as the header redbHttp.QueryParam.tag
var tag = ex.In.Headers.TryGetValue("redbHttp.QueryParam.tag", out var t)
? t?.ToString() ?? ""
: "";
// Server-side filter: the GET parameter goes straight into Where(...).
var found = await db.Query()
.Where(n => n.Tag == tag)
.ToListAsync();
Reply(ex, found.Select(o => new { o.Props.Tag, o.Props.Text }));
}).Log("Load ${header.redbHttp.QueryParam.tag}");
});
return context;
}
// inOut=true → whatever the body is at the end becomes the HTTP response.
private static void Reply(IExchange ex, object body)
{
ex.In.ContentType = "application/json";
ex.In.Body = JsonSerializer.Serialize(body);
}
}
/// Persisted note. [RedbScheme] marks the class as a redb schema.
[RedbScheme]
public sealed class Note
{
public string Tag { get; set; } = "";
public string Text { get; set; } = "";
}
Path: redb-route/demo/EchoWorkerDemo/EchoModule/manifest.json
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/demo/EchoWorkerDemo/EchoModule/manifest.json
----
{
"Name": "EchoModule",
"Version": "1.0.0",
"EntryPoints": ["EchoModule.dll"],
"Dependencies": []
}
Path: redb-route/demo/EchoWorkerDemo/EchoWorker/EchoWorker.csproj
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/demo/EchoWorkerDemo/EchoWorker/EchoWorker.csproj
----
Exe
net10.0
enable
enable
EchoWorker
false
Path: redb-route/demo/EchoWorkerDemo/EchoWorker/Program.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/demo/EchoWorkerDemo/EchoWorker/Program.cs
----
// ============================================================================
// EchoWorker — a debug host for the EchoModule Tsak module.
//
// It reproduces, in the smallest possible way, what the Tsak worker does:
// 1) stand redb up on SQLite (Free tier — the worker's default),
// 2) create the redb system tables once,
// 3) hand a RouteContext to EchoModule.InitRoute.main — the SAME entry point
// the worker calls, so no route code is duplicated here.
//
// Run it, then (PowerShell — JSON in single quotes; cmd.exe needs \" escaping instead):
// POST: curl.exe -X POST http://localhost:5099/api/notes -H "Content-Type: application/json" -d '{"tag":"work","text":"hello"}'
// GET: curl.exe "http://localhost:5099/api/notes?tag=work"
// ============================================================================
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using redb.Core; // IRedbService
using redb.Core.Extensions; // AddRedb
using redb.Core.Models.Configuration; // PropsSaveStrategy
using redb.SQLite.Pro.Extensions; // UseSqlite (tier-agnostic: AddRedb → Free)
using redb.SQLite.Data; // SqliteDataSource.NativeExtensionPath
using redb.Route.Core; // RouteContext
namespace EchoWorker;
public static class Program
{
public static async Task Main(string[] args)
{
// ── Free SQLite needs the native redb extension. The packaged Tsak worker ships
// it; running from source we point at the one built under redb.SQLite/native/build.
SqliteDataSource.NativeExtensionPath ??= ResolveNativeExtension();
// ── DI: console logging + redb on SQLite (single-file DB next to the exe) ──
var services = new ServiceCollection();
services.AddLogging(b => b
.AddSimpleConsole(o => { o.SingleLine = true; o.TimestampFormat = "HH:mm:ss "; })
.SetMinimumLevel(LogLevel.Information));
services.AddRedb(o => o
.UseSqlite("Data Source=echo_demo.db")
.Configure(c => c.PropsSaveStrategy = PropsSaveStrategy.DeleteInsert));
var sp = services.BuildServiceProvider();
// ── Create the redb system tables once (the worker does this on boot) ──
// ensureCreated: true builds the 13 base tables on a fresh SQLite file.
await sp.GetRequiredService().InitializeAsync(ensureCreated: true);
// ── Build a route context over that provider and call the module entry point ──
var ctx = new RouteContext(sp, contextId: "echo-worker");
ctx.AddService(typeof(ILoggerFactory), sp.GetRequiredService());
EchoModule.InitRoute.main(ctx); // <- the exact method the Tsak worker calls
await ctx.Start();
Console.WriteLine();
Console.WriteLine("EchoWorker running: http://localhost:5099/api/notes");
Console.WriteLine(" POST {\"tag\":\"work\",\"text\":\"hello\"} → save");
Console.WriteLine(" GET ?tag=work → list by tag");
Console.WriteLine("Ctrl+C to exit.");
Console.WriteLine();
var stop = new ManualResetEventSlim();
Console.CancelKeyPress += (_, e) => { e.Cancel = true; stop.Set(); };
stop.Wait();
await ctx.DisposeAsync();
}
// Walk up from the app dir to the repo's built Free SQLite native extension.
// Returns null when running from a packaged worker (it resolves the extension itself).
private static string? ResolveNativeExtension()
{
var suffix = OperatingSystem.IsWindows() ? ".dll"
: OperatingSystem.IsMacOS() ? ".dylib"
: ".so";
for (var dir = new DirectoryInfo(AppContext.BaseDirectory); dir != null; dir = dir.Parent)
{
// Public mirror layout first (redb.SQLite at the top level), then the development repository layout (redb.DB/src).
var candidate = Path.Combine(dir.FullName, "redb.SQLite", "native", "build", "redbsqlite" + suffix);
if (!File.Exists(candidate))
candidate = Path.Combine(dir.FullName, "redb.DB", "src", "redb.SQLite", "native", "build", "redbsqlite" + suffix);
if (File.Exists(candidate))
return candidate;
}
return null;
}
}
Path: redb-route/demo/EchoWorkerDemo/README.md
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/demo/EchoWorkerDemo/README.md
----
# EchoWorkerDemo — a minimal redb.Route module + a debug host
Two projects, one entry point. `InitRoute.main` is called by both the real Tsak
runtime and the debug host, so the route code is never duplicated.
```
EchoWorkerDemo/
├─ EchoModule/ <- the module (class library -> EchoModule.tpkg)
│ ├─ InitRoute.cs <- main(IRouteContext): 2 routes + the Note class
│ ├─ manifest.json <- { Name, Version, EntryPoints: ["EchoModule.dll"] }
│ └─ EchoModule.csproj <- + the PackTpkg target (zips manifest + DLL)
└─ EchoWorker/ <- the debug host (exe)
├─ Program.cs <- redb on SQLite + InitRoute.main(ctx) + Start
└─ EchoWorker.csproj
```
## Endpoints (one HTTP server, port 5099)
| Method | Path | What it does |
|---|---|---|
| POST | `/api/notes` | body `{"tag":"work","text":"hello"}` -> save a note into redb |
| GET | `/api/notes?tag=work` | return notes with that tag (`Where(n => n.Tag == tag).ToListAsync()`) |
Both routes share the same path and split on method via `?methods=POST` / `?methods=GET`;
a wrong method returns 405.
## Debug (no Tsak)
```bash
dotnet run --project EchoWorker
```
```powershell
# PowerShell: use curl.exe (curl is an alias for Invoke-WebRequest), JSON in single quotes
curl.exe -X POST http://localhost:5099/api/notes -H "Content-Type: application/json" -d '{"tag":"work","text":"hello"}'
curl.exe "http://localhost:5099/api/notes?tag=work"
```
```cmd
:: cmd.exe: escape the inner quotes
curl -X POST http://localhost:5099/api/notes -H "Content-Type: application/json" -d "{\"tag\":\"work\",\"text\":\"hello\"}"
```
Storage is `echo_demo.db` (SQLite, Free tier — the same tier the Tsak worker uses by default).
## Build the .tpkg and deploy to a worker
```bash
dotnet build EchoModule -c Debug
# -> EchoModule/output/EchoModule.tpkg (inside: EchoModule.dll + manifest.json + EchoModule.config.json)
```
Copy the `.tpkg` into the Tsak worker's module folder (`modules/`) — the worker picks it up
via hot-reload. `redb.Route.Http` / `redb.Route.Core` / `redb.Core` already ship in the worker's
shared libraries, so the `.tpkg` stays tiny (just the module DLL + descriptors).