Skip to content

Getting started: single-file lambda server first, raw string literals in step 2 - #160

Merged
Astn merged 1 commit into
masterfrom
getting-started-lambdas
Sep 25, 2026
Merged

Astn merged 1 commit into
masterfrom
getting-started-lambdas

Conversation

@Astn

@Astn Astn commented Sep 25, 2026

Copy link
Copy Markdown
Owner

The "Declare a service" step of Getting started now shows two examples, and the first is a complete server in one file.

Step 1

Example A is a .NET 10 file-based app (dotnet run server.cs, no project file) that registers two lambdas with ServiceBinder.BindMethod and serves them through Kestrel at /rpc. The code in the README was run against the published 2.0.0-preview.1 package and the exchange shown is the one observed:

curl -s -X POST http://127.0.0.1:5077/rpc -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"add","params":[1,2],"id":1}'
{"jsonrpc":"2.0","result":3.0,"id":1}

Also checked on the same server: greet with named params answers {"jsonrpc":"2.0","result":"hello you","id":2}, and a batch of one call plus one notification answers a one-element array. A sentence covers .NET 8 (same code in Program.cs, dotnet add package … --prerelease, drop the two #: lines).

Example B is the existing CalculatorService class, unchanged, followed by the existing notes. The session paragraph now says both examples use the default session, that lambdas and classes mix, and what a duplicate name does (BindMethod throws, a class bound afterwards replaces), since both examples register add.

Step 2

The in-process example uses raw string literals and a """…"""u8 literal for the byte call, so the JSON is readable and the byte[] plus AsSpan() workaround is gone from the example. The code was run against the published package and prints 3.0, 42 and 5.0 as the comments say.

The note about the byte overloads records what was measured with #:property LangVersion: a bare byte[] is ambiguous between the memory and span overloads on C# 12 and 13 (CS0121) and selects the span overload on C# 14 and later.

Package README

Json-Rpc/README.md mirrors both changes at shorter length.

site/build.py, render.py --check and test_render.py pass.

… in step 2

Step 1 now opens with a complete Kestrel server in one file: a .NET 10
file-based app that registers two lambdas with ServiceBinder.BindMethod
and maps them at /rpc, with the verified curl exchange. The
CalculatorService class follows as the second example, and the session
paragraph says what happens when both register the same name.

Step 2 uses raw string literals and a u8 literal for the byte call, so
the JSON is readable and the byte[]/AsSpan() workaround is no longer
needed in the example. The note records what was measured: a bare
byte[] is ambiguous on C# 12 and 13 and selects the span overload on
C# 14 and later.

The package README mirrors both changes at shorter length.
@Astn
Astn merged commit e581235 into master Sep 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant