Skip to content

Commit 9a821e4

Browse files
committed
A README written for the package pages
The core package shipped the repository README, which nuget.org renders without its HTML, relative links or images. Json-Rpc/README.md is written for that page: what the library is, the prerelease install line, the quick start from the repository README, the 1.2.3-versus-2.0 table with the headline chart from raw.githubusercontent.com, the companion packages, a short Upgrading from 1.x summary, and absolute links to the documentation site. It points a 1.x user at the What is new and Upgrading pages right after the install line, which is what Visual Studio shows when it opens the README on install. The companion READMEs open the same way, and the four package descriptions are shorter.
1 parent a7860da commit 9a821e4

8 files changed

Lines changed: 184 additions & 27 deletions

File tree

‎AustinHarris.JsonRpc.AspNetCore/AustinHarris.JsonRpc.AspNetCore.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Company>Austin Harris</Company>
55
<Authors>Austin Harris</Authors>
66
<Product>Json-Rpc.Net ASP.NET Core host</Product>
7-
<Description>ASP.NET Core / Kestrel hosting for JSON-RPC.Net: MapJsonRpc endpoint (PipeReader in, BodyWriter out, no strings), a raw Kestrel ConnectionHandler for JSON-RPC over TCP, and DI registration of services.</Description>
7+
<Description>ASP.NET Core hosting for AustinHarris.JsonRpc. Adds HTTP endpoints and raw Kestrel connections over TCP, Unix sockets and named pipes, with dependency injection.</Description>
88
<VersionPrefix>2.0.0</VersionPrefix>
99
<VersionSuffix>preview.1</VersionSuffix>
1010
<PackageReleaseNotes>2.0.0-preview.1, released with the core package. What is new: https://astn.github.io/JSON-RPC.NET/changelog.html. Upgrading from 1.x: https://astn.github.io/JSON-RPC.NET/upgrading.html</PackageReleaseNotes>

‎AustinHarris.JsonRpc.AspNetCore/README.md‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
# AustinHarris.JsonRpc.AspNetCore
1+
# `AustinHarris.JsonRpc.AspNetCore`
22

3-
Hosts [JSON-RPC.Net](https://github.com/Astn/JSON-RPC.NET) in ASP.NET Core. The core processes requests as
4-
UTF-8 bytes, so the HTTP endpoint reads the body with `PipeReader` and writes straight into
5-
`Response.BodyWriter`; nothing is turned into a string on the way through. A `ConnectionHandler` does the
6-
same for JSON-RPC over a raw Kestrel connection (TCP, Unix socket, named pipe).
3+
`AustinHarris.JsonRpc.AspNetCore` hosts
4+
[`AustinHarris.JsonRpc`](https://www.nuget.org/packages/AustinHarris.JsonRpc) 2.0 in ASP.NET Core
5+
and registers services through dependency injection.
6+
Choose it for an HTTP endpoint or raw Kestrel connections over TCP, Unix sockets or named pipes.
7+
8+
The HTTP endpoint reads with `PipeReader` and writes to `Response.BodyWriter`
9+
without converting the document to a string.
710

811
## Install
912

10-
```
11-
dotnet add package AustinHarris.JsonRpc.AspNetCore
13+
```sh
14+
dotnet add package AustinHarris.JsonRpc.AspNetCore --prerelease
1215
```
1316

1417
Targets `net8.0` and `net10.0`; depends on the `AustinHarris.JsonRpc` core package and the ASP.NET Core shared

‎AustinHarris.JsonRpc.Newtonsoft/AustinHarris.JsonRpc.Newtonsoft.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Company>Austin Harris</Company>
55
<Authors>Austin Harris</Authors>
66
<Product>Json-Rpc.Net Json.NET serializer</Product>
7-
<Description>Json.NET (Newtonsoft.Json) serializer for JSON-RPC.Net. Lenient parsing and full Json.NET conversion semantics; pass JsonSerializerSettings to control it.</Description>
7+
<Description>Json.NET serializer for AustinHarris.JsonRpc. Uses JsonSerializerSettings for converters, contract resolvers and lenient JSON input.</Description>
88
<VersionPrefix>2.0.0</VersionPrefix>
99
<VersionSuffix>preview.1</VersionSuffix>
1010
<PackageReleaseNotes>2.0.0-preview.1, released with the core package. What is new: https://astn.github.io/JSON-RPC.NET/changelog.html. Upgrading from 1.x: https://astn.github.io/JSON-RPC.NET/upgrading.html</PackageReleaseNotes>

‎AustinHarris.JsonRpc.Newtonsoft/README.md‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
# AustinHarris.JsonRpc.Newtonsoft
1+
# `AustinHarris.JsonRpc.Newtonsoft`
22

3-
Json.NET (Newtonsoft.Json) serializer for [JSON-RPC.Net](https://github.com/Astn/JSON-RPC.NET) 2.0.
3+
`AustinHarris.JsonRpc.Newtonsoft` adds Json.NET serialization to
4+
[`AustinHarris.JsonRpc`](https://www.nuget.org/packages/AustinHarris.JsonRpc) 2.0.
5+
Choose it when your models rely on Json.NET converters, contract resolvers or `[JsonProperty]`,
6+
or when clients send non-strict JSON.
47

5-
The core package (`AustinHarris.JsonRpc`) parses the JSON-RPC envelope itself and ships a built-in serializer for
6-
parameters and results that needs no JSON library. Install this package when you want Json.NET to do the value
7-
conversions: its converters, contract resolvers, `[JsonProperty]` attributes, date/float handling, and its
8-
tolerance for non-strict JSON.
8+
Configure parameter and result conversion with `JsonSerializerSettings`.
99

10-
```
11-
dotnet add package AustinHarris.JsonRpc.Newtonsoft
10+
## Install
11+
12+
```sh
13+
dotnet add package AustinHarris.JsonRpc.Newtonsoft --prerelease
1214
```
1315

1416
Targets `netstandard2.0`, `netstandard2.1`, `net8.0` and `net10.0`; depends on Newtonsoft.Json 13.0.4 and the

‎AustinHarris.JsonRpc.SystemTextJson/AustinHarris.JsonRpc.SystemTextJson.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Company>Austin Harris</Company>
55
<Authors>Austin Harris</Authors>
66
<Product>Json-Rpc.Net System.Text.Json serializer</Product>
7-
<Description>System.Text.Json serializer for JSON-RPC.Net. Utf8JsonReader/Utf8JsonWriter end to end; pass JsonSerializerOptions to control it.</Description>
7+
<Description>System.Text.Json serializer for AustinHarris.JsonRpc. Reads UTF-8 parameters and writes results directly to the response buffer, configured with JsonSerializerOptions.</Description>
88
<VersionPrefix>2.0.0</VersionPrefix>
99
<VersionSuffix>preview.1</VersionSuffix>
1010
<PackageReleaseNotes>2.0.0-preview.1, released with the core package. What is new: https://astn.github.io/JSON-RPC.NET/changelog.html. Upgrading from 1.x: https://astn.github.io/JSON-RPC.NET/upgrading.html</PackageReleaseNotes>

‎AustinHarris.JsonRpc.SystemTextJson/README.md‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
# AustinHarris.JsonRpc.SystemTextJson
1+
# `AustinHarris.JsonRpc.SystemTextJson`
22

3-
System.Text.Json serializer for [JSON-RPC.Net](https://github.com/Astn/JSON-RPC.NET) 2.0. The core parses the
4-
JSON-RPC envelope (method / params / id) itself and asks the serializer only to convert values: request
5-
parameters arrive as the raw UTF-8 bytes of one JSON value and go straight into `JsonSerializer.Deserialize`
6-
(no transcoding, no copies); results are written with a per-thread cached `Utf8JsonWriter` directly into the
3+
`AustinHarris.JsonRpc.SystemTextJson` adds `System.Text.Json` serialization to
4+
[`AustinHarris.JsonRpc`](https://www.nuget.org/packages/AustinHarris.JsonRpc) 2.0.
5+
Choose it when your application already uses `JsonSerializerOptions` and `System.Text.Json` converters.
6+
7+
Request parameters arrive as the raw UTF-8 bytes of one JSON value and go straight into `JsonSerializer.Deserialize`,
8+
with no transcoding and no copies. Results are written with a per-thread cached `Utf8JsonWriter` directly into the
79
response buffer.
810

911
## Install
1012

11-
```
12-
dotnet add package AustinHarris.JsonRpc.SystemTextJson
13+
```sh
14+
dotnet add package AustinHarris.JsonRpc.SystemTextJson --prerelease
1315
```
1416

1517
Targets `netstandard2.0`, `netstandard2.1`, `net8.0` and `net10.0`; depends on System.Text.Json 10.0.3 and the

‎Json-Rpc/AustinHarris.JsonRpc.csproj‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Company>Austin Harris</Company>
55
<Authors>Austin Harris</Authors>
66
<Product>Json-Rpc.Net Core</Product>
7-
<Description>JSON-RPC.Net is a high performance JSON-RPC 2.0 server for .NET Standard 2.0+ and modern .NET. Bytes in, bytes out, no JSON library dependency: the built-in serializer needs nothing, and Json.NET or System.Text.Json plug in through the companion packages. Host it in ASP.NET Core / Kestrel, a console app, sockets, pipes - anything that can hand you UTF-8 or a string.</Description>
7+
<Description>High-throughput JSON-RPC 2.0 server library for .NET Standard 2.0 through .NET 10: UTF-8 bytes in and out, no JSON library dependency, with Json.NET, System.Text.Json and ASP.NET Core hosting as companion packages.</Description>
88
<VersionPrefix>2.0.0</VersionPrefix>
99
<VersionSuffix>preview.1</VersionSuffix>
1010
<Copyright>Austin Harris</Copyright>
@@ -28,7 +28,7 @@
2828
</PropertyGroup>
2929

3030
<ItemGroup>
31-
<None Include="..\README.md" Pack="true" PackagePath="\" />
31+
<None Include="README.md" Pack="true" PackagePath="\" />
3232
<None Include="..\icon.png" Pack="true" PackagePath="\" />
3333
<InternalsVisibleTo Include="AustinHarris.JsonRpcTestN" />
3434
<InternalsVisibleTo Include="AustinHarris.JsonRpc.Micro" />

‎Json-Rpc/README.md‎

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# `AustinHarris.JsonRpc`
2+
3+
`AustinHarris.JsonRpc` is a JSON-RPC 2.0 server library for .NET.
4+
Give it a UTF-8 request document and receive the response document: bytes in, bytes out.
5+
It handles parsing, method dispatch, parameter binding, batches and error responses.
6+
You supply the transport.
7+
8+
The core has no JSON library dependency.
9+
Its built-in serializer works on its own; companion packages add Json.NET,
10+
`System.Text.Json` or ASP.NET Core hosting.
11+
12+
Targets `netstandard2.0`, `netstandard2.1`, `net8.0` and `net10.0`.
13+
This is a server library, with no client proxies or server-to-client calls.
14+
15+
## Install
16+
17+
2.0 is a prerelease. Include `--prerelease` when installing:
18+
19+
```sh
20+
dotnet add package AustinHarris.JsonRpc --prerelease
21+
```
22+
23+
Coming from 1.x? Read [What is new in 2.0](https://astn.github.io/JSON-RPC.NET/changelog.html) and [Upgrading from 1.x](https://astn.github.io/JSON-RPC.NET/upgrading.html) first.
24+
25+
## Getting started
26+
27+
### Declare a service
28+
29+
Create `CalculatorService.cs` with the service below.
30+
Derive from `JsonRpcService` and mark exposed methods with `[JsonRpcMethod]`.
31+
Constructing the service registers its methods in the default session.
32+
33+
```csharp
34+
using AustinHarris.JsonRpc;
35+
36+
public class CalculatorService : JsonRpcService
37+
{
38+
[JsonRpcMethod] // exposed as "add"
39+
private double add(double l, double r) => l + r;
40+
41+
[JsonRpcMethod("multiply")] // exposed under an explicit name
42+
public int Multiply(int l, int r) => l * r;
43+
44+
[JsonRpcMethod]
45+
public string StringMe(string x) => x;
46+
}
47+
```
48+
49+
Methods can be `private`. Parameters can be positional or named.
50+
Keep the service instance alive; it serves concurrent requests, so its state must be thread-safe.
51+
52+
### Process requests
53+
54+
Put this code in `Program.cs` in a console project targeting `net8.0` or `net10.0`.
55+
It calls the service through both string overloads and the byte entry point.
56+
The string overloads transcode into the byte pipeline.
57+
58+
```csharp
59+
using System;
60+
using System.Buffers;
61+
using System.Text;
62+
using AustinHarris.JsonRpc;
63+
64+
var service = new CalculatorService(); // binds itself to the default session; keep a reference
65+
66+
// Strings, asynchronous invocation.
67+
string response = await JsonRpcProcessor.ProcessAsync("{\"jsonrpc\":\"2.0\",\"method\":\"add\",\"params\":[1,2],\"id\":1}");
68+
// {"jsonrpc":"2.0","result":3.0,"id":1}
69+
70+
// Strings, synchronous, on the calling thread. Named parameters.
71+
string sync = JsonRpcProcessor.ProcessSync("{\"method\":\"multiply\",\"params\":{\"l\":6,\"r\":7},\"id\":2}");
72+
// {"jsonrpc":"2.0","result":42,"id":2}
73+
74+
// Bytes: the native path. The string overloads transcode into it.
75+
byte[] request = Encoding.UTF8.GetBytes("{\"method\":\"add\",\"params\":[2,3],\"id\":3}");
76+
var output = new ArrayBufferWriter<byte>();
77+
JsonRpcProcessor.Process(Handler.DefaultSessionId(), request.AsSpan(), output);
78+
Console.WriteLine(Encoding.UTF8.GetString(output.WrittenSpan)); // nothing is written for a notification
79+
```
80+
81+
The string responses appear in the comments above. The byte call prints:
82+
83+
```json
84+
{"jsonrpc":"2.0","result":5.0,"id":3}
85+
```
86+
87+
A batch returns an array when it contains calls that need responses.
88+
A notification has no `id` and produces no response.
89+
Pass a `byte[]` as `AsSpan()` to select the span overload.
90+
91+
Use `JsonRpcProcessor.ProcessAsync` for methods returning `Task` or `ValueTask`.
92+
The synchronous entry points do not await those methods.
93+
94+
## Performance
95+
96+
These results compare 1.2.3 and 2.0 with the same five requests on the same machine in one session.
97+
The 2.0 runs used the built-in serializer on an AMD Ryzen 7 7800X3D with .NET 10, Release and Server GC.
98+
99+
![JSON-RPC.Net 1.2.3 and 2.0 throughput through the string and byte entry points](https://raw.githubusercontent.com/Astn/JSON-RPC.NET/master/benchmarks/charts/headline-1x-vs-2.svg)
100+
101+
| Path | RPC/s | Against 1.2.3 |
102+
| --- | ---: | ---: |
103+
| 1.2.3, `Task<string> Process(string)`, thread pool, best batch size | 3.08 M | |
104+
| 2.0, the same string API and the same loop | 13.3 M | 4.3× |
105+
| 2.0, `Process(bytes)`, 16 dedicated threads | 31.7 M | 10.3× |
106+
| 2.0, `ProcessAsync(bytes)`, 16 awaited workers | 32.1 M | 10.4× |
107+
108+
These measurements cover the library without a transport.
109+
The asynchronous byte row uses methods that complete inline.
110+
For Kestrel TCP with 256 requests in flight per connection and `EnableAsyncMethods = false`,
111+
the measured range is 14.3 M to 16.5 M RPC/s on loopback, with clients and server on the same machine.
112+
113+
See the [benchmark tables](https://astn.github.io/JSON-RPC.NET/#benchmarks) for conditions
114+
and the [benchmark explorer](https://astn.github.io/JSON-RPC.NET/benchmarks/charts/explorer.html) for the data.
115+
116+
## Companion packages
117+
118+
Install only the integrations your host needs. Use matching package versions.
119+
120+
- [`AustinHarris.JsonRpc.Newtonsoft`](https://astn.github.io/JSON-RPC.NET/newtonsoft.html): Json.NET converters, contract resolvers, `[JsonProperty]`, `JsonSerializerSettings` and lenient input.
121+
- [`AustinHarris.JsonRpc.SystemTextJson`](https://astn.github.io/JSON-RPC.NET/systemtextjson.html): `System.Text.Json` conversion with `JsonSerializerOptions`, reading and writing UTF-8 values.
122+
- [`AustinHarris.JsonRpc.AspNetCore`](https://astn.github.io/JSON-RPC.NET/aspnetcore.html): HTTP endpoints, raw Kestrel connections over TCP, Unix sockets or named pipes, and dependency injection.
123+
124+
## Upgrading from 1.x
125+
126+
Most service methods can stay as they are. Review these changes before switching:
127+
128+
- Json.NET is now a companion package. Use it for `JsonSerializerSettings` and settings-based
129+
compatibility helpers; `JsonRequest.Params` follows the selected serializer's object model.
130+
- Review string overloads, especially calls with a positional null context.
131+
Name the `context` argument explicitly; serializer-taking overloads have changed.
132+
- Check client-visible behaviour: notifications never return responses, responding batches stay arrays,
133+
and version values, named parameters and conversion failures are validated.
134+
- Unhandled exceptions now return internal errors with exception details hidden by default.
135+
136+
[Upgrading from 1.x](https://astn.github.io/JSON-RPC.NET/upgrading.html) covers every API and wire change, and
137+
[What is new in 2.0](https://astn.github.io/JSON-RPC.NET/changelog.html) is the full changelog.
138+
139+
## Documentation
140+
141+
- [Server guide](https://astn.github.io/JSON-RPC.NET/)
142+
- [Hosting](https://astn.github.io/JSON-RPC.NET/#hosting)
143+
- [Configuration](https://astn.github.io/JSON-RPC.NET/#configuration)
144+
- [Errors and exception handling](https://astn.github.io/JSON-RPC.NET/#errors)
145+
- [Asynchronous methods and cancellation](https://astn.github.io/JSON-RPC.NET/#asynchronous-methods-and-cancellation)
146+
- [Security and host responsibilities](https://astn.github.io/JSON-RPC.NET/#security)
147+
- [What is new](https://astn.github.io/JSON-RPC.NET/changelog.html)
148+
- [Upgrading from 1.x](https://astn.github.io/JSON-RPC.NET/upgrading.html)
149+
- [Source repository](https://github.com/Astn/JSON-RPC.NET)
150+
- [MIT license](https://github.com/Astn/JSON-RPC.NET/blob/master/LICENSE)

0 commit comments

Comments
 (0)