|
17 | 17 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" |
18 | 18 | }; |
19 | 19 |
|
20 | | -var forecast = app.MapGroup( "/weatherforecast" ).WithApiVersionSet(); |
| 20 | +var forecast = app.MapApiGroup(); |
21 | 21 |
|
22 | 22 | // GET /weatherforecast?api-version=1.0 |
23 | | -forecast.MapGet( "/", () => |
| 23 | +forecast.MapGet( "/weatherforecast", () => |
24 | 24 | { |
25 | 25 | return Enumerable.Range( 1, 5 ).Select( index => |
26 | 26 | new WeatherForecast |
|
33 | 33 | .HasApiVersion( 1.0 ); |
34 | 34 |
|
35 | 35 | // GET /weatherforecast?api-version=2.0 |
36 | | -forecast.MapGet( "/", () => |
37 | | - { |
38 | | - return Enumerable.Range( 0, summaries.Length ).Select( index => |
39 | | - new WeatherForecast |
40 | | - ( |
41 | | - DateTime.Now.AddDays( index ), |
42 | | - Random.Shared.Next( -20, 55 ), |
43 | | - summaries[Random.Shared.Next( summaries.Length )] |
44 | | - ) ); |
45 | | - } ) |
46 | | - .HasApiVersion( 2.0 ); |
| 36 | +var v2 = forecast.MapGroup( "/weatherforecast" ) |
| 37 | + .HasApiVersion( 2.0 ); |
| 38 | + |
| 39 | +v2.MapGet( "/", () => |
| 40 | + { |
| 41 | + return Enumerable.Range( 0, summaries.Length ).Select( index => |
| 42 | + new WeatherForecast |
| 43 | + ( |
| 44 | + DateTime.Now.AddDays( index ), |
| 45 | + Random.Shared.Next( -20, 55 ), |
| 46 | + summaries[Random.Shared.Next( summaries.Length )] |
| 47 | + ) ); |
| 48 | + } ); |
47 | 49 |
|
48 | 50 | // POST /weatherforecast?api-version=2.0 |
49 | | -forecast.MapPost( "/", ( WeatherForecast forecast ) => { } ) |
50 | | - .HasApiVersion( 2.0 ); |
| 51 | +v2.MapPost( "/", ( WeatherForecast forecast ) => Results.Ok() ); |
51 | 52 |
|
52 | 53 | // DELETE /weatherforecast |
53 | | -forecast.MapDelete( "/", () => Results.NoContent() ) |
| 54 | +forecast.MapDelete( "/weatherforecast", () => Results.NoContent() ) |
54 | 55 | .IsApiVersionNeutral(); |
55 | 56 |
|
56 | 57 | app.Run(); |
|
0 commit comments