|
6 | 6 | builder.Services.AddApiVersioning();
|
7 | 7 |
|
8 | 8 | var app = builder.Build();
|
| 9 | +var versionSet = app.NewApiVersionSet() |
| 10 | + .HasApiVersion( 1.0 ) |
| 11 | + .HasApiVersion( 2.0 ) |
| 12 | + .ReportApiVersions() |
| 13 | + .Build(); |
9 | 14 |
|
10 | 15 | // Configure the HTTP request pipeline.
|
11 | 16 |
|
|
14 | 19 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
15 | 20 | };
|
16 | 21 |
|
17 |
| -app.DefineApi() |
18 |
| - .HasApiVersion( 1.0 ) |
19 |
| - .HasApiVersion( 2.0 ) |
20 |
| - .ReportApiVersions() |
21 |
| - .HasMapping( api => |
| 22 | +// GET /weatherforecast?api-version=1.0 |
| 23 | +app.MapGet( "/weatherforecast", () => |
22 | 24 | {
|
23 |
| - // GET /weatherforecast?api-version=1.0 |
24 |
| - api.MapGet( "/weatherforecast", () => |
25 |
| - { |
26 |
| - return Enumerable.Range( 1, 5 ).Select( index => |
27 |
| - new WeatherForecast |
28 |
| - ( |
29 |
| - DateTime.Now.AddDays( index ), |
30 |
| - Random.Shared.Next( -20, 55 ), |
31 |
| - summaries[Random.Shared.Next( summaries.Length )] |
32 |
| - ) ); |
33 |
| - } ) |
34 |
| - .MapToApiVersion( 1.0 ); |
35 |
| - |
36 |
| - // GET /weatherforecast?api-version=2.0 |
37 |
| - api.MapGet( "/weatherforecast", () => |
38 |
| - { |
39 |
| - return Enumerable.Range( 0, summaries.Length ).Select( index => |
40 |
| - new WeatherForecast |
41 |
| - ( |
42 |
| - DateTime.Now.AddDays( index ), |
43 |
| - Random.Shared.Next( -20, 55 ), |
44 |
| - summaries[Random.Shared.Next( summaries.Length )] |
45 |
| - ) ); |
46 |
| - } ) |
47 |
| - .MapToApiVersion( 2.0 ); |
48 |
| - |
49 |
| - // POST /weatherforecast?api-version=2.0 |
50 |
| - api.MapPost( "/weatherforecast", ( WeatherForecast forecast ) => { } ) |
51 |
| - .MapToApiVersion( 2.0 ); |
52 |
| - |
53 |
| - // DELETE /weatherforecast |
54 |
| - api.MapDelete( "/weatherforecast", () => { } ) |
55 |
| - .IsApiVersionNeutral(); |
56 |
| - } ); |
| 25 | + return Enumerable.Range( 1, 5 ).Select( index => |
| 26 | + new WeatherForecast |
| 27 | + ( |
| 28 | + DateTime.Now.AddDays( index ), |
| 29 | + Random.Shared.Next( -20, 55 ), |
| 30 | + summaries[Random.Shared.Next( summaries.Length )] |
| 31 | + ) ); |
| 32 | + } ) |
| 33 | + .UseApiVersioning( versionSet ) |
| 34 | + .MapToApiVersion( 1.0 ); |
| 35 | + |
| 36 | +// GET /weatherforecast?api-version=2.0 |
| 37 | +app.MapGet( "/weatherforecast", () => |
| 38 | + { |
| 39 | + return Enumerable.Range( 0, summaries.Length ).Select( index => |
| 40 | + new WeatherForecast |
| 41 | + ( |
| 42 | + DateTime.Now.AddDays( index ), |
| 43 | + Random.Shared.Next( -20, 55 ), |
| 44 | + summaries[Random.Shared.Next( summaries.Length )] |
| 45 | + ) ); |
| 46 | + } ) |
| 47 | + .UseApiVersioning( versionSet ) |
| 48 | + .MapToApiVersion( 2.0 ); |
| 49 | + |
| 50 | +// POST /weatherforecast?api-version=2.0 |
| 51 | +app.MapPost( "/weatherforecast", ( WeatherForecast forecast ) => { } ) |
| 52 | + .UseApiVersioning( versionSet ) |
| 53 | + .MapToApiVersion( 2.0 ); |
| 54 | + |
| 55 | +// DELETE /weatherforecast |
| 56 | +app.MapDelete( "/weatherforecast", () => { } ) |
| 57 | + .UseApiVersioning( versionSet ) |
| 58 | + .IsApiVersionNeutral(); |
57 | 59 |
|
58 | 60 | app.Run();
|
59 | 61 |
|
|
0 commit comments