Learn ASP.NET Core MVC with Swagger UI

Netkalon
2 min readOct 16, 2021

--

Swagger tooling for API’s build with asp.net core and it will generate beautiful API Documentation. Including UI to explore and test operations directly from your routes, controllers, and models. It requires minimal coding and maintenance, allowing you to focus on building an awesome API

In this Blog, we will learn ASP.NET Core MVC with testing API in swagger UI

What is swagger UI?

Swagger tooling for API’s build with asp.net core and it will generate beautiful API Documentation. Including UI to explore and test operations directly from your routes, Controllers and models. It requires minimal coding and maintenance, allowing you to focus on building an awesome API

Installing Swagger

Right click on your project. Select Manage NuGet Packages. We need to add this packages Swagger in browser tab. Once you installed in your project you can able to use you code.

Install over the package manager console

Swagger:

Install-Package Swashbuckle.AspNetCore.Swagger -Version 4.0.1

Using Swagger code for API

Open startup.cs file to add swagger service method

services.AddSwaggerGen(c =>

{

c.SwaggerDoc(“v1”, new Info { Title = “My API”, Version = “v1” });

});

Add the below line in you configure method

public void Configure(IApplicationBuilder app)

{

app.UseSwagger();

app.UseSwaggerUI(c =>

{

c.SwaggerEndpoint(“/swagger/v1/swagger.json”, “My API V1”);

});

app.UseMvc();

}

Right click on your project -> select Properties and go to “Debug” tab change the URL from default to swagger

Now run the application & you will see the swagger UI based result

We can able to see in swagger with JSON format

You can download this solution from GitHub URL

--

--