Skip to content

Commit 767220f

Browse files
Refactor Minimal API support to remove code forked from ASP.NET Core. Relates to #751
1 parent 96ae9c4 commit 767220f

31 files changed

+1071
-2017
lines changed

examples/AspNetCore/WebApi/MinimalApiExample/Program.cs

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
builder.Services.AddApiVersioning();
77

88
var app = builder.Build();
9+
var versionSet = app.NewApiVersionSet()
10+
.HasApiVersion( 1.0 )
11+
.HasApiVersion( 2.0 )
12+
.ReportApiVersions()
13+
.Build();
914

1015
// Configure the HTTP request pipeline.
1116

@@ -14,46 +19,43 @@
1419
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
1520
};
1621

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", () =>
2224
{
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();
5759

5860
app.Run();
5961

0 commit comments

Comments
 (0)