步骤
1、新建MinimalAPI项目
2、更新Program.cs
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", async (HttpContext context) =>
{
await context.Response.WriteAsync("GET - Hello World");
});
app.MapPost("/", async (HttpContext context) =>
{
await context.Response.WriteAsync("POST - Hello World");
});
app.Run();
结果
通过Postman测试,
Get方法得到GET - Hello World
Post方法得到POST - Hello World
Gitee获取源码: