LiteAPI.Core
1.1.3
dotnet add package LiteAPI.Core --version 1.1.3
NuGet\Install-Package LiteAPI.Core -Version 1.1.3
<PackageReference Include="LiteAPI.Core" Version="1.1.3" />
<PackageVersion Include="LiteAPI.Core" Version="1.1.3" />
<PackageReference Include="LiteAPI.Core" />
paket add LiteAPI.Core --version 1.1.3
#r "nuget: LiteAPI.Core, 1.1.3"
#:package LiteAPI.Core@1.1.3
#addin nuget:?package=LiteAPI.Core&version=1.1.3
#tool nuget:?package=LiteAPI.Core&version=1.1.3
LiteAPI
LiteAPI is a minimal, dependency-free C# micro web framework for building lightweight REST APIs, internal tools, and small services with a simple middleware pipeline, routing, and binding.
Installation
NuGet:
dotnet add package LiteAPI.Core
Package Manager:
Install-Package LiteAPI.Core
Requirements: .NET 9.0 (the package currently targets net9.0).
Features
- Signature-based routing with route params (including trailing wildcard
{*path}) - Binding:
[FromBody],[FromForm],[FromQuery],[FromRoute] - Middleware pipeline (logging, CORS, auth/authz, compression, rate limiting, etc.)
- Authentication (API key / Bearer token) + Authorization (roles + policies)
- Static file serving (
app.MapStaticFiles()) - OpenAPI generation (
app.UseOpenApi()) - Production hardening defaults:
- Concurrency limiting (
MaxConcurrentRequests) - Request body size limit with 413 Payload Too Large (
MaxRequestBodyBytes) - Request body is read at most once for binding
- Concurrency limiting (
- Observability helpers:
X-Request-Id(app.UseRequestId())- Minimal metrics (
app.UseMetrics()) - Health endpoint (
app.MapHealthz())
Quick start
using LiteAPI;
using LiteAPI.Features.Auth;
var builder = LiteWebApplication.CreateBuilder(args);
builder.AddAuthentication(auth =>
{
auth.DefaultScheme = AuthScheme.Bearer;
auth.ValidateBearerToken = token => token == "secret-token";
});
builder.AddAuthorization(authz =>
{
authz.AddPolicy("AdminOnly", ctx =>
ctx.Headers.TryGetValue("X-Role", out var role) && role == "Admin");
});
var app = builder.Build();
app.UseLogging();
app.UseRequestId();
app.UseMetrics();
app.MapHealthz();
app.UseRateLimiting(maxRequests: 20, perSeconds: 10, perIp: true);
app.UseCompression(minBytes: 512);
app.UseAuthentication();
app.UseAuthorization();
app.Get("/", () => Response.Ok("Hello from LiteAPI"))
.AllowAnonymous();
app.Get("/api/users/{id}", ([FromRoute] int id) =>
Response.OkJson(new { id }))
.RequireRoles("Admin");
app.Post("/echo", ([FromBody] EchoDto dto) => Response.OkJson(dto));
app.MapStaticFiles();
var options = new LiteServerOptions
{
MaxConcurrentRequests = 128,
MaxRequestBodyBytes = 64 * 1024
};
// Managed hosting (HttpListener)
// app.Run(options);
// Rust TCP listener hosting (same middleware/router pipeline)
app.RunWithRust(options);
public record EchoDto(string Message);
Hosting modes
LiteAPI can run in two modes:
- Managed (default):
app.Run(...)usesHttpListener. - Rust listener:
app.RunWithRust(...)uses an embedded Rust TCP listener that parses HTTP, calls into the same managed middleware/router pipeline, then returns a full HTTP response.
Cross-platform native packaging
The NuGet package can ship the Rust native library under runtimes/<rid>/native/ (CI/release builds).
Currently supported RIDs:
win-x64,win-arm64linux-x64,linux-arm64osx-x64,osx-arm64
Handler parameter guidelines (important)
- Prefer host-independent handler signatures (works for both managed and Rust modes):
- primitives +
[FromRoute]/[FromQuery] - DTOs via
[FromBody]/[FromForm] LiteAPI.Http.LiteRequestif you need headers/query/body stream
- primitives +
HttpListenerRequestis only available in managed mode; in Rust mode it is not present.
Contributing / building native locally
To build and copy the Rust native library into the correct runtimes/<rid>/native/ folder:
- Windows:
powershell -File scripts/build-rust-native.ps1 -Rid win-x64 - Linux/macOS:
bash scripts/build-rust-native.sh linux-x64(orosx-arm64, etc.)
Roadmap
Next planned (high-level):
- Caching middleware
- Request validation extensions
- CLI scaffolding for generating LiteAPI projects
License
MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.