Headless.Api.Core
0.4.15
dotnet add package Headless.Api.Core --version 0.4.15
NuGet\Install-Package Headless.Api.Core -Version 0.4.15
<PackageReference Include="Headless.Api.Core" Version="0.4.15" />
<PackageVersion Include="Headless.Api.Core" Version="0.4.15" />
<PackageReference Include="Headless.Api.Core" />
paket add Headless.Api.Core --version 0.4.15
#r "nuget: Headless.Api.Core, 0.4.15"
#:package Headless.Api.Core@0.4.15
#addin nuget:?package=Headless.Api.Core&version=0.4.15
#tool nuget:?package=Headless.Api.Core&version=0.4.15
Headless.Api.Core
Building blocks for ASP.NET Core APIs — primitives only. Provides service registration helpers, middleware, problem details, JWT, identity, security headers, and request-context abstractions.
Looking for
AddHeadless(),UseHeadless(),MapHeadlessEndpoints()? Those live inHeadless.Api.ServiceDefaults. This package is the parts catalog; ServiceDefaults is the assembly.
When to Use This Package
Pull Headless.Api.Core directly when you need à la carte primitives without the framework orchestrator — for example, registering AddHeadlessProblemDetails() alone, or composing your own middleware pipeline without the default order.
For the standard one-line bootstrap, use Headless.Api.ServiceDefaults instead. It transitively brings in this package.
Installation
dotnet add package Headless.Api.Core
Key Features
- Problem details standardization via
AddHeadlessProblemDetails()(registersHeadlessApiExceptionHandlercovering tenancy, conflict, validation, not-found, EF concurrency, timeout, not-implemented, and cancellation) - Response compression (Brotli, Gzip) via
AddHeadlessApiResponseCompression() - Antiforgery via
AddHeadlessAntiforgery() - JWT token factory and claims principal handling
- HSTS security configuration
- API versioning integration
- Device detection (
IWebClientInfoProvider) - Idempotency middleware (
AddIdempotencyMiddleware()) - Server timing middleware
- Request cancellation handling
- Diagnostic listeners for debugging (
AddHeadlessApiDiagnosticListeners) - Status codes rewriter (
AddStatusCodesRewriterMiddleware()) - Kestrel limits and default API conventions via
ConfigureHeadlessDefaultApi()
Building Blocks Quick Reference
services.AddHeadlessProblemDetails();
services.AddHeadlessApiResponseCompression();
services.AddHeadlessAntiforgery();
services.AddStatusCodesRewriterMiddleware();
services.ConfigureHeadlessDefaultApi(); // Kestrel limits, lowercase URLs, HSTS, default 'self' health check
services.AddIdempotencyMiddleware(...);
services.AddServerTimingMiddleware();
Tenant resolution primitives:
builder.AddHeadlessMultiTenancy(options => options.ClaimType = UserClaimTypes.TenantId);
app.UseTenantResolution();
Exception Mapping
AddHeadlessProblemDetails() registers a single IExceptionHandler (HeadlessApiExceptionHandler) that maps framework exceptions to normalized ProblemDetails responses. Covers any unhandled exception that bubbles to ASP.NET Core's exception-handler middleware — typically MVC actions and Minimal-API endpoints. Middleware running before UseExceptionHandler, hosted/background services, and SignalR hubs need their own catch sites.
| Exception | Response |
|---|---|
MissingTenantContextException |
400 (identified by error.code: g:tenant-required) |
CrossTenantWriteException |
409 (identified by error.code: g:cross-tenant-write) |
ConflictException |
409 with errors |
FluentValidation.ValidationException |
422 with field errors |
EntityNotFoundException |
404 |
EF Core DbUpdateConcurrencyException (matched by type name) |
409 with concurrency-failure error |
TimeoutException |
408 |
NotImplementedException |
501 |
OperationCanceledException (or inner OCE at any depth) when HttpContext.RequestAborted is the source |
499 (no body — client closed request) |
OCEs from other sources (server-side timeouts surfaced by RequestTimeoutsMiddleware, library-thrown OCEs whose cancellation token is not RequestAborted) are intentionally not mapped here — the handler returns false so the platform default or a downstream handler can render them.
Prerequisites: call app.UseExceptionHandler() to wire the IExceptionHandler chain into the pipeline.
Tenancy response shape (other exceptions follow the same normalization):
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "bad-request",
"status": 400,
"detail": "An operation required an ambient tenant context but none was set.",
"error": {
"code": "g:tenant-required",
"description": "An operation required an ambient tenant context but none was set."
},
"traceId": "...",
"buildNumber": "...",
"commitNumber": "...",
"instance": "/path",
"timestamp": "..."
}
The body deliberately surfaces no entity name, exception message, Exception.Data tag, or inner exception — those belong in server logs, not API responses. Clients route on the stable error.code and status values.
Dependencies
Headless.Api.AbstractionsHeadless.CoreHeadless.MultiTenancyHeadless.Security.AbstractionsHeadless.SecurityHeadless.Caching.AbstractionsHeadless.FluentValidationHeadless.Api.FluentValidationHeadless.HostingAsp.Versioning.HttpDeviceDetector.NETFluentValidationMicrosoft.Extensions.Http.ResilienceNetEscapades.AspNetCore.SecurityHeaders
| 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
- Asp.Versioning.Abstractions (>= 10.0.0)
- Asp.Versioning.Http (>= 10.0.0)
- CommunityToolkit.HighPerformance (>= 8.4.2)
- DeviceDetector.NET (>= 6.5.0)
- FileSignatures (>= 7.2.0)
- FluentValidation (>= 12.1.1)
- FluentValidation.DependencyInjectionExtensions (>= 12.1.1)
- Headless.Api.Abstractions (>= 0.4.15)
- Headless.Api.FluentValidation (>= 0.4.15)
- Headless.Caching.Abstractions (>= 0.4.15)
- Headless.Core (>= 0.4.15)
- Headless.FluentValidation (>= 0.4.15)
- Headless.Hosting (>= 0.4.15)
- Headless.MultiTenancy (>= 0.4.15)
- Headless.Security (>= 0.4.15)
- Humanizer.Core (>= 3.0.10)
- IdGen (>= 3.0.7)
- JetBrains.Annotations (>= 2025.2.4)
- libphonenumber-csharp (>= 9.0.30)
- Microsoft.AspNetCore.MiddlewareAnalysis (>= 10.0.8)
- Microsoft.Bcl.TimeProvider (>= 10.0.8)
- Microsoft.Extensions.DiagnosticAdapter (>= 3.1.32)
- Microsoft.Extensions.Http.Resilience (>= 10.6.0)
- Microsoft.Extensions.Telemetry.Abstractions (>= 10.6.0)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.18.0)
- morelinq (>= 4.4.0)
- NetEscapades.AspNetCore.SecurityHeaders (>= 1.3.1)
- Nito.AsyncEx (>= 5.1.2)
- Nito.Disposables (>= 2.5.0)
- OpenMcdf (>= 3.1.3)
- Polly.Core (>= 8.6.6)
- Polly.Extensions (>= 8.6.4)
- Polly.RateLimiting (>= 8.6.4)
- Scrutor (>= 7.0.0)
- Snappier (>= 1.3.1)
- System.Reactive (>= 6.1.0)
- TimeZoneConverter (>= 7.2.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Headless.Api.Core:
| Package | Downloads |
|---|---|
|
Headless.Api.ServiceDefaults
Package Description |
|
|
Headless.Api.MinimalApi
Package Description |
|
|
Headless.Api.Mvc
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.