ASP.NET Core web API with Swagger
All Code
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc(“SwaggerExample”, new OpenApiInfo
{
Title = “Web Api Core Swagger Example”,
Version = “5.6.0”,
Description = “Swagger with ASP.NET Core 3.1”,
Contact = new OpenApiContact
{
Email = “ilhandemirtepe65@gmail.com”,
Name = “İlhan Demirtepe”
}
});
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseSwagger().UseSwaggerUI(c =>
{
c.SwaggerEndpoint(“/swagger/SwaggerExample/swagger.json”, “Swagger Example”);
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}