Getting started: single-file lambda server first, raw string literals in step 2 - #160
Merged
Merged
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withServiceBinder.BindMethodand serves them through Kestrel at/rpc. The code in the README was run against the published2.0.0-preview.1package and the exchange shown is the one observed:{"jsonrpc":"2.0","result":3.0,"id":1}Also checked on the same server:
greetwith 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 inProgram.cs,dotnet add package … --prerelease, drop the two#:lines).Example B is the existing
CalculatorServiceclass, 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 (BindMethodthrows, a class bound afterwards replaces), since both examples registeradd.Step 2
The in-process example uses raw string literals and a
"""…"""u8literal for the byte call, so the JSON is readable and thebyte[]plusAsSpan()workaround is gone from the example. The code was run against the published package and prints3.0,42and5.0as the comments say.The note about the byte overloads records what was measured with
#:property LangVersion: a barebyte[]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.mdmirrors both changes at shorter length.site/build.py,render.py --checkandtest_render.pypass.