Swagger UI is a browser interface for exploring and testing an API. It displays endpoints and schemas from a Swagger/OpenAPI description, then lets you send requests without switching to curl or Postman. OpenAPI names the specification; Swagger remains a familiar name for its tooling. section 5.5
Listing 5.28 Adding Swagger to Program.cs
var builder = WebApplication.CreateBuilder(args); builder.Services.AddDbContext<CatalogContext>(); builder.Services.AddControllers(); builder.Services.AddSwaggerGen(); #1 var app = builder.Build(); app.UseHttpsRedirection(); app.MapControllers(); app.UseSwagger(); #1 app.UseSwaggerUI(); #1 // ... app.Run();
Add `Swashbuckle.AspNetCore`, then register Swagger generation with `AddSwaggerGen()` and enable the document and interface with `UseSwagger()` and `UseSwaggerUI()` in `Program.cs`. section 5.5
Run the application and open `https://localhost:<port>/swagger/index.html`. If `dotnet watch` does not pick up the configuration changes and the Swagger URLs fail, stop and restart the process. section 5.5
Try a controller request
Expand `GET /Catalog`, select **Try It Out**, enter any parameters, and execute the request to inspect the response. The same interface is useful when testing controller actions that create, update, or delete books with non-GET requests. section 5.5
Swagger UI can also authenticate with an identity provider and send bearer tokens to APIs. That capability is distinct from the basic setup and request-testing flow shown here. section 9.7


