CosmoApiServer.Core 1.8.2

There is a newer version of this package available.
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
                    
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="CosmoApiServer.Core" Version="1.8.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CosmoApiServer.Core" Version="1.8.2" />
                    
Directory.Packages.props
<PackageReference Include="CosmoApiServer.Core" />
                    
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 CosmoApiServer.Core --version 1.8.2
                    
#r "nuget: CosmoApiServer.Core, 1.8.2"
                    
#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 CosmoApiServer.Core@1.8.2
                    
#: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=CosmoApiServer.Core&version=1.8.2
                    
Install as a Cake Addin
#tool nuget:?package=CosmoApiServer.Core&version=1.8.2
                    
Install as a Cake Tool

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 parsingHttp11Parser uses ReadOnlySpan<byte> and SequenceReader<byte> directly over the pipe buffer.
  • Zero-allocation Headers — Headers are stored as ReadOnlyMemory<byte> and only materialized to strings if accessed.
  • Lazy DI scopeLazyScopeProvider only calls IServiceProvider.CreateScope() if a service is actually resolved.
  • Object PoolingHttpContext, HttpRequest, and HttpResponse are pooled and reused to eliminate GC pressure.
  • Async State Machine RenderingRenderTreeBuilder uses a struct-based command buffer for non-blocking, high-speed SSR.
  • Span-based routingRouteTable uses a ConcurrentDictionary cache and span-based matching for O(1) lookups.

Features

  • HTTP/1.1 keep-alive (pipelined)
  • HTTP/2 (h2c cleartext + ALPN over TLS)
  • TLS via SslStream with ALPN (h2 / http/1.1)
  • Razor Components — Full .razor support with @page, [Parameter], and CascadingParameters
  • Routable Components — Components can define their own routes via @page without 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, custom IMiddleware)
  • 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 ServingHttpResponse.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's HttpResponse buffers using an optimized async state machine.
  • Routable: Use @page "/my-route" directly in your .razor files.
  • Cascading Parameters: Share state (like ModelState or User) down the component tree automatically.
  • Validation: Support for DataAnnotations with 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed