Add Swagger to .NET Minimal APIs (So You Can Test Endpoints in the Browser)
Full Stack Software Developer with 5+ years of experience building and maintaining web and mobile applications using .NET, ASP.NET, SQL,Angular and Ionic.
Currently working in the healthcare domain as both a developer and Product Owner on a cross-platform application (iOS, Android, Web). Experienced in integrating AI solutions (ChatGPT API) to optimize user workflows and reduce manual effort.
Strong background in Agile/Scrum environments, collaborating closely with team leaders as a Scrum Master, involved in sprint planning, Jira management, and stakeholder communication.
If you want your API to feel professional, add OpenAPI (Swagger). It gives you:
interactive docs
“Try it out” buttons
request/response examples
Step 1 — Install Swagger package
In your project folder:
dotnet add package Swashbuckle.AspNetCore
Step 2 — Update Program.cs
Add these lines near the top:
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
Then enable Swagger in the app pipeline before mapping endpoints:
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
Optional: make endpoints show better names in Swagger:
group.MapGet("/", (TodoService service) => Results.Ok(service.GetAll()))
.WithName("ListTodos")
.WithSummary("List all todos");
group.MapPost("/", (TodoCreateDto dto, TodoService service) => { ... })
.WithName("CreateTodo")
.WithSummary("Create a new todo");
If your .WithSummary(...) doesn’t compile, remove it and keep .WithName(...) (your .NET SDK might require different packages/versions). The core idea still works.
Step 3 — Run and open Swagger UI
Run:
dotnet run
Open:
/swagger
Now you can test:
POST todo with JSON body
GET list
PUT update
DELETE
External link:
- Swagger / OpenAPI concept: https://swagger.io/specification/