RouteVersioning 1.0.0-alpha.1
See the version list below for details.
dotnet add package RouteVersioning --version 1.0.0-alpha.1
NuGet\Install-Package RouteVersioning -Version 1.0.0-alpha.1
<PackageReference Include="RouteVersioning" Version="1.0.0-alpha.1" />
<PackageVersion Include="RouteVersioning" Version="1.0.0-alpha.1" />
<PackageReference Include="RouteVersioning" />
paket add RouteVersioning --version 1.0.0-alpha.1
#r "nuget: RouteVersioning, 1.0.0-alpha.1"
#:package RouteVersioning@1.0.0-alpha.1
#addin nuget:?package=RouteVersioning&version=1.0.0-alpha.1&prerelease
#tool nuget:?package=RouteVersioning&version=1.0.0-alpha.1&prerelease
RouteVersioning
Route-based API versioning for ASP.NET Core. This library works by exhaustively mapping all corresponding API versions, on startup. Only minimal APIs are currently supported.
Still a work in progress!! The examples below will likely change as I finalise its APIs. My to-do list is:
- Minimal APIs
- OpenAPI
- Sunset header
- Tests
- Controllers, if possible?
- Target lower .NET versions?
- NuGet package
If you're looking for a library that supports other versioning schemes (query parameters, request
headers, content negotiation, etc.), consider
Asp.Versioning
which is more versatile, and
should be capable of everything that this library offers with some configuration.
Comparatively, this library,
- Offers just one API versioning scheme (route-based).
- Maps all versions at startup, instead of (as I understand) resolving API versions as requests come through.
- Uses API version ranges (i.e., vX-onward/between vX & Y inclusive) by default.
Usage
Mapping a Versioned API
Define all available API versions with a
RouteVersionSetBuilder
.// In this case, the API has 3 versions. var versions = new RouteVersionSetBuilder<int>() .Version(1) .Version(2) .Version(3) .Build();
Use
WithVersions
to map versioned endpoints, specifying the range of versions to which they apply.var api = app.MapGroup("api").WithVersions(versions);
Use
From
to map an endpoint that is available from a specific version onward.// api/v1/a (introduced) // api/v2/a (unchanged) // api/v3/a (unchanged) api.From(1).MapGet("a", () => ...); // api/v2/b (introduced) // api/v3/b (unchanged) api.From(2).MapGet("b", () => ...); // api/v3/c (introduced) api.From(3).MapGet("c", () => ...);
Use
Between
to map an endpoint that is available in all versions within an inclusive range of versions.// api/v1/d (introduced) // api/v2/d (unchanged; retired) api.Between(1, 2).MapGet("d", () => ...);
Combine the two to revise an endpoint at a specific version.
// api/v1/e (introduced) // api/v2/e (unchanged) api.Between(1, 2).MapGet("e", () => ...); // api/v3/e (revised) api.From(3).MapGet("e", () => ...);
Retiring an API Version
Use
Sunset
to indicate an API version being retired, which adds the specified details asSunset
andLink
headers as described in RFC 8594, to its responses.var versions = new RouteVersionSetBuilder<int>() .Version(1, (v) => v .Sunset( at: someDateTime, link: "https://example.com/changelog/v2-migration", linkMediaType: "text/html" ) ) .Build();
HTTP/1.1 200 OK Sunset: Tue, 24 Dec 2024 12:41:24 GMT Link: <https://example.com/changelog/v2-migration>; rel="sunset"; type="text/html"
Adding Endpoint Conventions
To add a convention that applies to a specific endpoint across a range of API versions (
v*/a
), add a convention as you normally would, after theMap*
call.api.Between(1, 2).MapGet("a", () => ...).AddEndpointFilter<UwuifyFilter>(); api.From(3).MapGet("a", () => ...).AddEndpointFilter<UwuifyFilter>();
To add a convention that applies to all endpoints of a specific API version (
v1/*
), use the configuration delegate ofRouteVersionSetBuilder.Version
.var versions = new RouteVersionSetBuilder<int>() .Version(1, (v) => v .AddEndpointFilter<IEndpointConventionBuilder, UwuifyFilter>() ) .Build();
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 (1)
Showing the top 1 NuGet packages that depend on RouteVersioning:
Package | Downloads |
---|---|
RouteVersioning.OpenApi
OpenAPI document generation for RouteVersioning. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0-alpha.4 | 81 | 1/27/2025 |
1.0.0-alpha.3 | 75 | 1/27/2025 |
1.0.0-alpha.2 | 77 | 1/25/2025 |
1.0.0-alpha.1 | 80 | 1/25/2025 |