HydraServer 0.1.0-alpha.1
dotnet add package HydraServer --version 0.1.0-alpha.1
NuGet\Install-Package HydraServer -Version 0.1.0-alpha.1
<PackageReference Include="HydraServer" Version="0.1.0-alpha.1" />
<PackageVersion Include="HydraServer" Version="0.1.0-alpha.1" />
<PackageReference Include="HydraServer" />
paket add HydraServer --version 0.1.0-alpha.1
#r "nuget: HydraServer, 0.1.0-alpha.1"
#:package HydraServer@0.1.0-alpha.1
#addin nuget:?package=HydraServer&version=0.1.0-alpha.1&prerelease
#tool nuget:?package=HydraServer&version=0.1.0-alpha.1&prerelease
Hydra
A simple streaming webserver that runs anywhere .NET 6 runs
Why
ASP.NET Core doesn't support running on MAUI targets (Android, iOS, etc.). It's also pretty bulky and, in my opinion, extremely annoying to use for small to medium sized projects. After trying alternatives for a project without finding anyting satisfying, a friend made a joke about writing our own. Two days of hyperfocusing later I'm writing this readme.
Unlike ASP, Hydra is very simple and barebones. I like to think it exists at an abstraction level where it's both usable as is and for building frameworks upon. However, it doesn't support HTTP/2.0 and is nowhere near as feature packed as ASP.
Unlike most alternatives, Hydra is a fully streaming server. Request and response bodies are streams, and handling can start as soon as the method and URI parsed without waiting for the full headers and body. Under the hood, it uses a streaming parser based on httparse and is built on top of System.IO.Pipelines.
Finally, Hydra is unsurprising. It never tries to be smart and only does the bare minimum required to follow the spec.
Features
- Simple and lightweight
- Truly cross-platform
- Streaming request and response bodies
- Streaming request headers
- TLS encryption
- Request pipelining
- Chunked encoding
- Unix socket support
- WebSockets (in progress)
Usage
You can take a look at usage examples in the example project and run them using dotnet run --project Hydra.Example -- <EXAMPLE> [<HOSTNAME>] [<PORT>]
Basic
using Hydra;
using System.Text;
using var server = await Server.At("localhost", 8080, async (req) =>
{
var hello = "Hello, Hydra!";
var body = new MemoryStream(Encoding.UTF8.GetBytes(hello));
var res = new HttpResponse(200, body);
return res;
});
await server.Run();
TLS
using var server = await Server.At(hostname, port, handler);
await server.Tls("./tls/cert.pem", "./tls/key.rsa");
await server.Run();
Unix
var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP);
socket.Bind(new UnixDomainSocketEndPoint(path));
socket.Listen();
using var server = new Server(socket, handler);
await server.Run();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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 was computed. 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 was computed. 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. |
-
net6.0
- HydraServer.Http11 (>= 0.1.0-alpha.1)
- HydraServer.WebSocket13 (>= 0.1.0-alpha.1)
- Microsoft.Extensions.Primitives (>= 6.0.0)
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 |
---|---|---|
0.1.0-alpha.1 | 152 | 2/26/2023 |