API Versioning
Granit.ApiVersioning configures URL-based API versioning using
Asp.Versioning.
Primary reader: URL segment (/api/v{version:apiVersion}/resource).
Fallback reader: query string (?api-version=1.0).
[DependsOn(typeof(GranitApiVersioningModule))]public class AppModule : GranitModule { }{ "ApiVersioning": { "DefaultMajorVersion": 1, "ReportApiVersions": true }}var v1 = app.NewVersionedApi("Appointments").MapGroup("/api/v{version:apiVersion}");
var v1Group = v1.MapGroup("/appointments").HasApiVersion(1);v1Group.MapGet("/", GetAppointments);v1Group.MapPost("/", CreateAppointment);
var v2Group = v1.MapGroup("/appointments").HasApiVersion(2);v2Group.MapGet("/", GetAppointmentsV2);Deprecation headers (RFC 8594)
Section titled “Deprecation headers (RFC 8594)”Mark endpoints as deprecated with automatic Deprecation, Sunset, and Link
response headers:
v1Group.MapGet("/legacy-patients", GetLegacyPatients) .Deprecated(sunsetDate: "2026-06-01", link: "https://docs.example.com/migration/v2");Response headers:
Deprecation: trueSunset: Sun, 01 Jun 2026 00:00:00 GMTLink: <https://docs.example.com/migration/v2>; rel="deprecation"Each call to a deprecated endpoint is logged at Warning level.
Configuration reference
Section titled “Configuration reference”| Property | Default | Description |
|---|---|---|
DefaultMajorVersion | 1 | Default API version when client does not specify one |
ReportApiVersions | true | Include api-supported-versions and api-deprecated-versions headers |
Public API summary
Section titled “Public API summary”| Category | Key types | Package |
|---|---|---|
| Module | GranitApiVersioningModule | — |
| Options | GranitApiVersioningOptions | Granit.ApiVersioning |
| Attributes | DeprecatedAttribute | Granit.ApiVersioning |
| Extensions | AddGranitApiVersioning(), .Deprecated() | Granit.ApiVersioning |
See also
Section titled “See also”- API Documentation — Scalar OpenAPI, multi-version docs
- API & Http overview — All HTTP infrastructure packages