Skip to content

Commit

Permalink
Refactor Minimal API support to remove code forked from ASP.NET Core.…
Browse files Browse the repository at this point in the history
… Relates to #751
  • Loading branch information
commonsensesoftware committed May 8, 2022
1 parent 96ae9c4 commit 767220f
Show file tree
Hide file tree
Showing 31 changed files with 1,071 additions and 2,017 deletions.
80 changes: 41 additions & 39 deletions examples/AspNetCore/WebApi/MinimalApiExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
builder.Services.AddApiVersioning();

var app = builder.Build();
var versionSet = app.NewApiVersionSet()
.HasApiVersion( 1.0 )
.HasApiVersion( 2.0 )
.ReportApiVersions()
.Build();

// Configure the HTTP request pipeline.

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

app.DefineApi()
.HasApiVersion( 1.0 )
.HasApiVersion( 2.0 )
.ReportApiVersions()
.HasMapping( api =>
// GET /weatherforecast?api-version=1.0
app.MapGet( "/weatherforecast", () =>
{
// GET /weatherforecast?api-version=1.0
api.MapGet( "/weatherforecast", () =>
{
return Enumerable.Range( 1, 5 ).Select( index =>
new WeatherForecast
(
DateTime.Now.AddDays( index ),
Random.Shared.Next( -20, 55 ),
summaries[Random.Shared.Next( summaries.Length )]
) );
} )
.MapToApiVersion( 1.0 );
// GET /weatherforecast?api-version=2.0
api.MapGet( "/weatherforecast", () =>
{
return Enumerable.Range( 0, summaries.Length ).Select( index =>
new WeatherForecast
(
DateTime.Now.AddDays( index ),
Random.Shared.Next( -20, 55 ),
summaries[Random.Shared.Next( summaries.Length )]
) );
} )
.MapToApiVersion( 2.0 );
// POST /weatherforecast?api-version=2.0
api.MapPost( "/weatherforecast", ( WeatherForecast forecast ) => { } )
.MapToApiVersion( 2.0 );
// DELETE /weatherforecast
api.MapDelete( "/weatherforecast", () => { } )
.IsApiVersionNeutral();
} );
return Enumerable.Range( 1, 5 ).Select( index =>
new WeatherForecast
(
DateTime.Now.AddDays( index ),
Random.Shared.Next( -20, 55 ),
summaries[Random.Shared.Next( summaries.Length )]
) );
} )
.UseApiVersioning( versionSet )
.MapToApiVersion( 1.0 );

// GET /weatherforecast?api-version=2.0
app.MapGet( "/weatherforecast", () =>
{
return Enumerable.Range( 0, summaries.Length ).Select( index =>
new WeatherForecast
(
DateTime.Now.AddDays( index ),
Random.Shared.Next( -20, 55 ),
summaries[Random.Shared.Next( summaries.Length )]
) );
} )
.UseApiVersioning( versionSet )
.MapToApiVersion( 2.0 );

// POST /weatherforecast?api-version=2.0
app.MapPost( "/weatherforecast", ( WeatherForecast forecast ) => { } )
.UseApiVersioning( versionSet )
.MapToApiVersion( 2.0 );

// DELETE /weatherforecast
app.MapDelete( "/weatherforecast", () => { } )
.UseApiVersioning( versionSet )
.IsApiVersionNeutral();

app.Run();

Expand Down
Loading

0 comments on commit 767220f

Please sign in to comment.