Yllibed.HttpServer.Json
1.0.0-dev.24
dotnet add package Yllibed.HttpServer.Json --version 1.0.0-dev.24
NuGet\Install-Package Yllibed.HttpServer.Json -Version 1.0.0-dev.24
<PackageReference Include="Yllibed.HttpServer.Json" Version="1.0.0-dev.24" />
<PackageVersion Include="Yllibed.HttpServer.Json" Version="1.0.0-dev.24" />
<PackageReference Include="Yllibed.HttpServer.Json" />
paket add Yllibed.HttpServer.Json --version 1.0.0-dev.24
#r "nuget: Yllibed.HttpServer.Json, 1.0.0-dev.24"
#:package Yllibed.HttpServer.Json@1.0.0-dev.24
#addin nuget:?package=Yllibed.HttpServer.Json&version=1.0.0-dev.24&prerelease
#tool nuget:?package=Yllibed.HttpServer.Json&version=1.0.0-dev.24&prerelease
Yllibed Http Server – JSON Adapter
Helpers for building JSON endpoints and JSON SSE (Server‑Sent Events) with Yllibed.HttpServer, powered by Newtonsoft.Json.
What it provides
- JsonHandlerBase<TResult>: base class to implement JSON endpoints quickly (sets content-type, serializes response, handles errors)
- Query string parsing helper built‑in to the base class (multi‑value aware)
- JSON serialization using Newtonsoft.Json
- SSE helpers: SendJsonAsync and SendJsonEventAsync to push compact JSON over text/event-stream
Quick start – JSON endpoint
Implement a small handler that returns an object. The adapter serializes it to application/json and writes the proper status code.
using Yllibed.HttpServer;
using Yllibed.HttpServer.Json;
public sealed class MyResult
{
public string? A { get; set; }
public string? B { get; set; }
}
public sealed class MyHandler : JsonHandlerBase<MyResult>
{
public MyHandler() : base("GET", "/api/echo") { }
protected override async Task<(MyResult result, ushort statusCode)> ProcessRequest(
CancellationToken ct,
string relativePath,
IDictionary<string, string[]> query)
{
await Task.Yield();
query.TryGetValue("a", out var a);
query.TryGetValue("b", out var b);
return (new MyResult { A = a?.FirstOrDefault(), B = b?.FirstOrDefault() }, 200);
}
}
var server = new Server();
server.RegisterHandler(new MyHandler());
var (uri4, _) = server.Start();
Console.WriteLine(uri4 + "api/echo?a=1&b=2");
Response body:
{
"A": "1",
"B": "2"
}
Quick start – JSON over SSE
Send JSON directly as SSE data using the extension methods.
using Yllibed.HttpServer.Sse;
using Yllibed.HttpServer.Json;
public sealed class PricesSse : SseHandler
{
protected override bool ShouldHandle(IHttpServerRequest req, string path)
=> base.ShouldHandle(req, path) && path == "/prices";
protected override async Task HandleSseSession(ISseSession sse, CancellationToken ct)
{
await sse.SendJsonEventAsync("tick", new { Bid = 1.2345, Ask = 1.2347 }, id: "1", ct: ct);
}
}
The JSON is serialized compact (no whitespace) and placed in the SSE data field.
Behavior and details
- Content type: application/json for JsonHandlerBase responses
- Serializer: Newtonsoft.Json with Formatting.Indented for HTTP responses; Formatting.None for SSE
- Errors in your handler are caught and a 500 text/plain response is emitted. Log output uses Microsoft.Extensions.Logging via the server’s logger
- Paths can be passed with or without leading slash; base class normalizes them
- Method matching is case‑insensitive
When to use
- Build small JSON APIs without bringing a full web framework
- Add real‑time JSON updates over SSE easily
Package info
- Package: Yllibed.HttpServer.Json
- Depends on: Yllibed.HttpServer, Newtonsoft.Json
- Targets: see solution TargetFrameworks
See also
For server setup, routing helpers, SSE basics, and DI, check the main project README: ../Yllibed.HttpServer/README.md or the repository root README.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Logging (>= 9.0.8)
- Newtonsoft.Json (>= 13.0.3)
- PolySharp (>= 1.15.0)
- System.Collections.Immutable (>= 9.0.8)
- System.Diagnostics.DiagnosticSource (>= 9.0.8)
- System.ValueTuple (>= 4.6.1)
- Yllibed.HttpServer (>= 1.0.0-dev.24)
-
net8.0
- Microsoft.Extensions.Logging (>= 9.0.8)
- Newtonsoft.Json (>= 13.0.3)
- PolySharp (>= 1.15.0)
- System.Diagnostics.DiagnosticSource (>= 9.0.8)
- Yllibed.HttpServer (>= 1.0.0-dev.24)
-
net9.0
- Microsoft.Extensions.Logging (>= 9.0.8)
- Newtonsoft.Json (>= 13.0.3)
- PolySharp (>= 1.15.0)
- Yllibed.HttpServer (>= 1.0.0-dev.24)
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 |
---|---|---|
1.0.0-dev.24 | 86 | 9/6/2025 |
1.0.0-dev.21 | 51 | 9/6/2025 |
1.0.0-dev.17 | 49 | 9/6/2025 |
1.0.0-dev.16 | 50 | 9/6/2025 |
1.0.0-dev.13 | 79 | 9/5/2025 |
1.0.0-dev.11 | 124 | 4/30/2025 |
1.0.0-dev.10.ge2ac37743f | 73 | 11/24/2024 |
1.0.0-dev.8.gf43e0359cb | 71 | 11/24/2024 |
1.0.0-dev.7.g14d4754916 | 81 | 11/24/2024 |
1.0.0-dev.6.g4ad889b55a | 67 | 11/24/2024 |
1.0.0-dev.3.ga376bac550 | 80 | 11/24/2024 |
0.9.1 | 2,610 | 5/31/2017 |
0.9.0 | 1,149 | 5/31/2017 |