How to use Swagger UI on a .NET 9 Web API project

If you didn’t know, with the release of .NET 9, Swagger UI for Web API projects no longer comes out of the box. This tutorial will show you how to add Swagger configuration to .NET 9 projects.

First, create a new ASP .NET Core Web API project and set …


This content originally appeared on DEV Community and was authored by Olabamiji Oyetubo

If you didn’t know, with the release of .NET 9, Swagger UI for Web API projects no longer comes out of the box. This tutorial will show you how to add Swagger configuration to .NET 9 projects.

First, create a new ASP .NET Core Web API project and set your target framework to .NET 9

Create Project

Next, navigate to the package manager console.

Go to Package manager Console
Once there, use the Browse tab to search for Swashbuckle.AspNetCore, then click install to add it to your project

Install Swashbuckle

After the package has been successfully installed, navigate to your Program.cs class and just above the builder.Build() method, add this line of code;

builder.Services.AddSwaggerGen();

This method registers the Swagger generator into the DI container, allowing your application to generate an OpenAPI specification for our API.
Next, modify the app.Environment.IsDevelopment() condition, so it looks like this;

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseSwagger() serves the API documentation as OpenAPI JSON, while app.UseSwaggerUI() provides an interactive UI for testing endpoints.
Your Program.cs should look like this now;

Updated Program.cs
Now, when you run your application, the server and port name should be generated in a prompt like so;

Server and port
To see the Swagger UI, on your browse, Simply add /swagger/index.html to your server and port number.

Swagger UI page

Happy Coding!!


This content originally appeared on DEV Community and was authored by Olabamiji Oyetubo


Print Share Comment Cite Upload Translate Updates
APA

Olabamiji Oyetubo | Sciencx (2025-02-09T15:39:13+00:00) How to use Swagger UI on a .NET 9 Web API project. Retrieved from https://www.scien.cx/2025/02/09/how-to-use-swagger-ui-on-a-net-9-web-api-project/

MLA
" » How to use Swagger UI on a .NET 9 Web API project." Olabamiji Oyetubo | Sciencx - Sunday February 9, 2025, https://www.scien.cx/2025/02/09/how-to-use-swagger-ui-on-a-net-9-web-api-project/
HARVARD
Olabamiji Oyetubo | Sciencx Sunday February 9, 2025 » How to use Swagger UI on a .NET 9 Web API project., viewed ,<https://www.scien.cx/2025/02/09/how-to-use-swagger-ui-on-a-net-9-web-api-project/>
VANCOUVER
Olabamiji Oyetubo | Sciencx - » How to use Swagger UI on a .NET 9 Web API project. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/02/09/how-to-use-swagger-ui-on-a-net-9-web-api-project/
CHICAGO
" » How to use Swagger UI on a .NET 9 Web API project." Olabamiji Oyetubo | Sciencx - Accessed . https://www.scien.cx/2025/02/09/how-to-use-swagger-ui-on-a-net-9-web-api-project/
IEEE
" » How to use Swagger UI on a .NET 9 Web API project." Olabamiji Oyetubo | Sciencx [Online]. Available: https://www.scien.cx/2025/02/09/how-to-use-swagger-ui-on-a-net-9-web-api-project/. [Accessed: ]
rf:citation
» How to use Swagger UI on a .NET 9 Web API project | Olabamiji Oyetubo | Sciencx | https://www.scien.cx/2025/02/09/how-to-use-swagger-ui-on-a-net-9-web-api-project/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.