Configure Swagger in dotnet core web api

 1. Install the Swashbuckle.AspNetCore NuGet package:

   You can do this via the NuGet Package Manager Console with the following command:

  

   Install-Package Swashbuckle.AspNetCore


2. Configure Swagger in the Programme.cs file:


   Open the Programme.cs file and add the following code to configure Swagger:


    builder.Services.AddEndpointsApiExplorer();

    builder.Services.AddSwaggerGen(c =>

    {

        c.SwaggerDoc("v1", new OpenApiInfo

        {

            Version = "v1",

            Title = "My API",

        });

    });


    // Configure the HTTP request pipeline.

    if (app.Environment.IsDevelopment())

    {

        app.UseSwagger();

        app.UseSwaggerUI(c =>

        {

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

        });

    }


3. configure LaunchSettings.json file:

   launchBrowser : true,

   lanuchUrl : "swagger"


Comments

Popular posts from this blog

Publish or Host webapi on IIS