- ASP.NET Core MVC
- ASP.NET Core logging with Serilog
- ASP.NET Core managed config
- ASP.NET Core MVC with /api/-area
- ASP.NET Core API versioning
- ASP.NET Core API with Swagger UI
- ASP.NET Core EF in separate project
- ASP.NET Core AutoMapper
- ASP.NET Core response cache
- ASP.NET Core memory cache
- ASP.NET Core TypeScript
Swagger makes the API machine readable. This means documentation and client implementations can be produced automatically. Swashbuckle runs top of Swagger and provides an UI. Together they provide nice functionality for documenting and testing your API.
Install
1 |
Install-Package Swashbuckle.AspNetCore |
Implement
In Startup.cs ConfigureServices:
1 2 3 4 |
services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1"}); }); |
In Configure:
1 2 3 4 5 6 |
app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint($"/swagger/v1/swagger.json", "My API"); c.RoutePrefix = "api"; }); |
RoutePrefix is required when API is located under /api/.
Note that Swagger is sensitive to errors in Controller, i.e. missing [HttpGet] or similar. You can get a hint of what is wrong by visiting /swagger/v1/swagger.json.
Test
Navigate to /api/-folder of website.
