- Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathProgram.cs
38 lines (34 loc) · 1.07 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
usingMicrosoft.AspNetCore.Mvc;
varbuilder=WebApplication.CreateBuilder();
builder.Services.AddControllersWithViews();
builder.Services.AddApiVersioning(o =>o.ReportApiVersions=true);
varapp=builder.Build();
app.MapDefaultControllerRoute();
app.Run();
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]")]
[ApiController]
publicclassHelloWorldController:ControllerBase
{
[HttpGet]
publicIActionResultGet(ApiVersionapiVersion)=>Ok(new{Controller=GetType().Name,Version=apiVersion.ToString()});
}
publicclassHomeController:Controller
{
publicActionResultIndex()
{
returnnewContentResult
{
Content=@"
<html>
<body>
<ul>
<li><a href=""/api/v1/helloWorld"">Click here for Version 1</a></li>
<li><a href=""/api/v2/helloWorld"">Click here for Version 2</a></li>
</ul>
</body>
</html>",
ContentType="text/html"
};
}
}