CosmoApiServer.Core
1.8.2
See the version list below for details.
dotnet add package CosmoApiServer.Core --version 1.8.2
NuGet\Install-Package CosmoApiServer.Core -Version 1.8.2
<PackageReference Include="CosmoApiServer.Core" Version="1.8.2" />
<PackageVersion Include="CosmoApiServer.Core" Version="1.8.2" />
<PackageReference Include="CosmoApiServer.Core" />
paket add CosmoApiServer.Core --version 1.8.2
#r "nuget: CosmoApiServer.Core, 1.8.2"
#:package CosmoApiServer.Core@1.8.2
#addin nuget:?package=CosmoApiServer.Core&version=1.8.2
#tool nuget:?package=CosmoApiServer.Core&version=1.8.2
CosmoApiServer
A high-performance, zero-dependency HTTP server framework for .NET 10, built entirely on System.IO.Pipelines and System.Net.Sockets.
No DotNetty. No ASP.NET. No Kestrel. Just raw sockets → pipes → your handlers.
Benchmark
ApacheBench · c=50 concurrent · n=5,000 requests · keep-alive · macOS arm64
| Scenario | CosmoApiServer | ASP.NET Core Kestrel | Advantage |
|---|---|---|---|
| GET /ping | 53,159 req/s | 17,053 req/s | +212% |
| GET /items (20-item list) | 42,752 req/s | 15,759 req/s | +171% |
| POST /echo (JSON body) | 54,624 req/s | 17,943 req/s | +204% |
Zero failed requests. Performance holds at c=200 (53,874 req/s).
Razor Component Rendering (100-row table)
| Framework | Throughput | P50 Latency | Advantage |
|---|---|---|---|
| CosmoApiServer | 4,235 ops/sec | 0.24 ms | +141% |
| Blazor SSR (Static) | 1,754 ops/sec | 0.57 ms | Baseline |
Why so fast?
Traditional .NET HTTP servers (including Kestrel and DotNetty-based servers) have at least one thread-pool context switch per request. CosmoApiServer eliminates this:
Socket → PipeWriter → PipeReader → Parser → Middleware → PipeWriter → Socket
Everything runs inline on the connection task. No EventLoop→ThreadPool hand-off. No intermediate byte arrays. No string allocation on the hot path.
Key design decisions:
- Zero-copy parsing —
Http11ParserusesReadOnlySpan<byte>andSequenceReader<byte>directly over the pipe buffer. - Zero-allocation Headers — Headers are stored as
ReadOnlyMemory<byte>and only materialized to strings if accessed. - Lazy DI scope —
LazyScopeProvideronly callsIServiceProvider.CreateScope()if a service is actually resolved. - Object Pooling —
HttpContext,HttpRequest, andHttpResponseare pooled and reused to eliminate GC pressure. - Async State Machine Rendering —
RenderTreeBuilderuses a struct-based command buffer for non-blocking, high-speed SSR. - Span-based routing —
RouteTableuses aConcurrentDictionarycache and span-based matching for O(1) lookups.
Features
- HTTP/1.1 keep-alive (pipelined)
- HTTP/2 (h2c cleartext + ALPN over TLS)
- TLS via
SslStreamwith ALPN (h2/http/1.1) - Razor Components — Full
.razorsupport with@page,[Parameter], andCascadingParameters - Routable Components — Components can define their own routes via
@pagewithout a controller - Attribute-based controllers (
[HttpGet],[HttpPost],[Route],[Authorize]) - Convention-based routing (
MapGet,MapPost, …) - JSON request/response (
WriteJson,ReadJson<T>) IAsyncEnumerable<T>→ NDJSON streaming response- Middleware pipeline (
UseLogging,UseCors,UseJwtAuthentication, customIMiddleware) - WebSockets (
HttpContext.AcceptWebSocketAsync()) - OpenAPI & Swagger UI auto-generation
- Security Middlewares (CSRF, HSTS, HTTPS Redirection, CSRF Validation)
- Model Validation via DataAnnotations (Controllers & Components)
- Zero-Copy File Serving —
HttpResponse.SendFileAsync()streams directly from disk to socket
Razor Components
CosmoApiServer includes a first-class implementation of Razor Components (similar to Blazor SSR). This provides the power of Razor syntax (C# + HTML) with the performance of a zero-dependency framework.
Why Razor Components?
- High Performance: Renders directly to
CosmoApiServer'sHttpResponsebuffers using an optimized async state machine. - Routable: Use
@page "/my-route"directly in your.razorfiles. - Cascading Parameters: Share state (like
ModelStateorUser) down the component tree automatically. - Validation: Support for
DataAnnotationswith built-in<ValidationSummary />.
Usage
Create a .razor file in your project:
@page "/hello/{Name}"
@inherits Microsoft.AspNetCore.Components.ComponentBase
<h1>Hello, @Name!</h1>
<div class="alert alert-success">
Current Time: @DateTime.Now
</div>
@code {
[Parameter] public string Name { get; set; }
}
Enable in Program.cs:
var builder = CosmoWebApplicationBuilder.Create()
.AddRazorComponents(); // Scans for @page components
Projects in this repository
| Project | Description |
|---|---|
src/CosmoApiServer.Core |
Core framework library |
samples/BlazorSqlSample |
Replicated Blazor structure with SQL streaming and components |
samples/WeatherApp |
Full REST API: JWT auth, DI, streaming, CosmoSQLClient |
templates/CosmoRazorServerTemplate |
dotnet new cosmorazor template |
tests/CosmoApiServer.Core.Tests |
68+ unit tests for routing, middleware, components, validation |
Credits
Razor Components in CosmoApiServer is inspired by Microsoft Blazor, but implemented as a lightweight, SSR-only engine focused on raw performance and zero dependencies.
Portions of the templating engine are based on the excellent RazorSlices project by Damian Edwards, licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Cosmo.Transport (>= 1.0.2)
- Microsoft.Extensions.Configuration (>= 10.0.1)
- Microsoft.Extensions.Configuration.CommandLine (>= 10.0.1)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.1)
- Microsoft.Extensions.Configuration.Json (>= 10.0.1)
- Microsoft.Extensions.DependencyInjection (>= 10.0.1)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Logging (>= 10.0.1)
- System.IdentityModel.Tokens.Jwt (>= 8.16.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CosmoApiServer.Core:
| Package | Downloads |
|---|---|
|
CosmoS3
Amazon S3-compatible object storage server built on CosmoApiServer.Core. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.2.3 | 112 | 4/12/2026 |
| 3.2.1 | 108 | 4/12/2026 |
| 3.2.0 | 82 | 4/12/2026 |
| 3.1.0 | 81 | 4/12/2026 |
| 3.0.3 | 79 | 4/11/2026 |
| 3.0.2 | 99 | 4/10/2026 |
| 3.0.1 | 96 | 4/9/2026 |
| 3.0.0 | 218 | 4/4/2026 |
| 2.1.4 | 90 | 4/3/2026 |
| 2.1.3 | 87 | 4/3/2026 |
| 2.1.2 | 80 | 4/3/2026 |
| 2.1.1 | 82 | 4/3/2026 |
| 2.1.0 | 82 | 4/3/2026 |
| 2.0.9 | 83 | 4/3/2026 |
| 2.0.8 | 81 | 4/3/2026 |
| 2.0.7 | 91 | 4/3/2026 |
| 2.0.6 | 91 | 4/2/2026 |
| 2.0.5 | 115 | 4/1/2026 |
| 2.0.4 | 82 | 4/1/2026 |
| 1.8.2 | 83 | 3/19/2026 |