Yllibed.HttpServer 1.0.0-dev.17

This is a prerelease version of Yllibed.HttpServer.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Yllibed.HttpServer --version 1.0.0-dev.17
                    
NuGet\Install-Package Yllibed.HttpServer -Version 1.0.0-dev.17
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Yllibed.HttpServer" Version="1.0.0-dev.17" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Yllibed.HttpServer" Version="1.0.0-dev.17" />
                    
Directory.Packages.props
<PackageReference Include="Yllibed.HttpServer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Yllibed.HttpServer --version 1.0.0-dev.17
                    
#r "nuget: Yllibed.HttpServer, 1.0.0-dev.17"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Yllibed.HttpServer@1.0.0-dev.17
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Yllibed.HttpServer&version=1.0.0-dev.17&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Yllibed.HttpServer&version=1.0.0-dev.17&prerelease
                    
Install as a Cake Tool

Yllibed Http Server

A versatile, lightweight HTTP server for .NET applications. Self-contained with no ASP.NET dependency. Ideal for tools, local services, test harnesses, IoT and desktop apps.

Features

  • Single-assembly, minimal footprint, no external web framework
  • Plug-in handler model: register one or many handlers; first to respond wins
  • IPv4 and IPv6 support; returns both URIs from Start()
  • Dynamic port assignment (Port = 0) to avoid conflicts (recommended)
  • Microsoft.Extensions.DependencyInjection integration and IOptions<ServerOptions>
  • Server-Sent Events (SSE) helper base class for real-time event streams
  • Static content responses and simple REST-style endpoints
  • Runs on .NET (see package TargetFrameworks)

Quick Start

// Recommended: Use dynamic port assignment
var server = new Server(); // Port 0 by default - no conflicts!
server.RegisterHandler(new StaticHandler("/", "text/plain", "Hello, world!"));
var (uri4, uri6) = server.Start();
Console.WriteLine($"Server running at: {uri4}");

Or with a fixed port:

var server = new Server(8080);
server.RegisterHandler(new StaticHandler("/", "text/plain", "Hello, world!"));
var (uri4, uri6) = server.Start();

Common Use Cases

  • OAuth2 return URL endpoints
  • Remote diagnostics/monitoring
  • IoT device configuration interfaces
  • Simple REST API endpoints

Configuration

Dynamic port assignment (recommended): using port 0 automatically selects a free TCP port, preventing conflicts—perfect for tests, parallel runs and local tools.

// ✅ Recommended approach
var server = new Server(); // Port 0 by default
var (uri4, uri6) = server.Start();
var actualPort = new Uri(uri4).Port; // Discover the assigned port

For advanced configuration, use ServerOptions:

var serverOptions = new ServerOptions
{
    Port = 0, // Dynamic port (recommended)
    Hostname4 = "127.0.0.1",
    Hostname6 = "::1",
    BindAddress4 = IPAddress.Any // Listen on all interfaces
};
var server = new Server(serverOptions);

Dependency Injection

Works with Microsoft.Extensions.DependencyInjection:

// Option 1: Extension method (cleanest) - uses dynamic ports by default
services.AddYllibedHttpServer(); // Zero configuration, no conflicts!

// Or configure explicitly:
services.AddYllibedHttpServer(opts =>
{
    opts.Port = 0; // Dynamic port (recommended)
    opts.Hostname4 = "127.0.0.1";
});

// Option 2: Configure + AddSingleton
services.Configure<ServerOptions>(opts => { opts.Port = 0; });
services.AddSingleton<Server>(); // Auto-selects IOptions<> constructor

Handlers and Routing

  • Handlers are small classes implementing IHttpHandler. You can register multiple handlers; they are queried in order and the first one to produce a response wins.
  • Use RelativePathHandler to compose simple routing trees under a base path.

Example:

var server = new Server();
var api = new RelativePathHandler("/api");
api.RegisterHandler(new StaticHandler("/ping", "text/plain", "pong"));
server.RegisterHandler(api);
server.Start();

Server-Sent Events (SSE)

Stream real-time events over HTTP using the SseHandler base class or StartSseSession extension.

public sealed class MySseHandler : SseHandler
{
    protected override bool ShouldHandle(IHttpServerRequest req, string path)
        => base.ShouldHandle(req, path) && path == "/sse";

    protected override async Task HandleSseSession(ISseSession sse, CancellationToken ct)
    {
        for (var i = 0; i < 5 && !ct.IsCancellationRequested; i++)
        {
            await sse.SendEventAsync($"tick {i}", eventName: "tick", id: i.ToString(), ct: ct);
            await Task.Delay(1000, ct);
        }
    }
}

var root = new RelativePathHandler("/");
root.RegisterHandler(new MySseHandler());
server.RegisterHandler(root);

Design goals

  • Keep things tiny and dependency-free
  • Prefer clarity over features; you own the control flow in your handlers
  • Make local and internal scenarios painless (dynamic ports, simple DI)

Limitations

  • HTTP/1.1 only (no HTTP/2+ or WebSockets)
  • No HTTPS/TLS support
  • Designed for small-scale applications

For more examples and advanced usage, visit the GitHub repository: https://github.com/carldebilly/Yllibed.HttpServer

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Yllibed.HttpServer:

Package Downloads
Yllibed.HttpServer.Json

JSON adapter for Yllibed.HttpServer using Newtonsoft.Json

Yllibed.HttpServer.Nancy

NancyFx adapter for Yllibed Versatile Http Server

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-dev.24 51 9/6/2025
1.0.0-dev.21 53 9/6/2025
1.0.0-dev.17 46 9/6/2025
1.0.0-dev.16 49 9/6/2025
1.0.0-dev.13 80 9/5/2025
1.0.0-dev.11 127 4/30/2025
1.0.0-dev.10.ge2ac37743f 79 11/24/2024
1.0.0-dev.8.gf43e0359cb 75 11/24/2024
1.0.0-dev.7.g14d4754916 78 11/24/2024
1.0.0-dev.6.g4ad889b55a 74 11/24/2024
1.0.0-dev.3.ga376bac550 74 11/24/2024
0.9.1 2,959 5/31/2017
0.9.0 1,585 5/31/2017