Learn ASP.NET Core MVC with Swagger UI


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


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.UseSwaggerUI(c =>
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");


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

1 comment

  1. web D school 1 August, 2019 at 00:01 Reply

    Fantastic post however, I was wanting to know if you could
    write a little more on this topic? I’d be very grateful if you could
    elaborate a little bit more. Thanks

Leave a Reply to web D school Cancel reply