-
Notifications
You must be signed in to change notification settings - Fork 717
Expand file tree
/
Copy pathMultiVersionedController.cs
More file actions
30 lines (26 loc) · 1.23 KB
/
MultiVersionedController.cs
File metadata and controls
30 lines (26 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
namespace ApiVersioning.Examples.Controllers;
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
[ApiVersion( 1.0 )]
[ApiVersion( 2.0 )]
[ApiVersion( 3.0 )]
[Route( "api/v{version:apiVersion}/[controller]" )]
public class MultiVersionedController : ControllerBase
{
// Shared across all versions.
[HttpGet]
public string Get( ApiVersion version ) => "Version " + version;
// [MapToApiVersion] — exact-match. Reachable ONLY for v2.0.
// Requests under v1.0 or v3.0 receive the configured
// UnsupportedApiVersionStatusCode (default 400).
[HttpGet( "legacy" ), MapToApiVersion( 2.0 )]
public string GetLegacy( ApiVersion version ) => "Legacy " + version;
// [IntroducedInApiVersion] — "from this version onward against the
// controller's declared set." Reachable for v2.0 AND v3.0 automatically.
// Requests under v1.0 receive the per-attribute status (default 404)
// — distinguishable from "version unknown" (still 400).
// When v4.0 is added to the controller's [ApiVersion] declarations,
// this action becomes reachable for v4.0 with no further changes.
[HttpGet( "modern" ), IntroducedInApiVersion( 2.0 )]
public string GetModern( ApiVersion version ) => "Modern " + version;
}