与标准默认WebApi区别:
缺少:

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();   

app.UserHttpsRedirection();
app.UseAuthorization();
app.MapControllers();


var builder = webApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello world!");
var app =webApplication .Create(args);
app.MapGet("/", () => "This is a GET");
app.MapPost("/",()=> "This is a POST");
app.MapPut("/", () => "This is a PUT");
app.MapDeleteC"/", () => "This is a DELETE");
app.Run();

这里的第一个参数可以进行路由约束,如app. MapGet("/posts/ {slug:regex(^[a-z0-9_ -]+5)}",(string slug) => $"Post
{slug}");

标签: none

添加新评论