Web API -Project

ASP.NET Core Web API Project template

If a Web API has Swagger (or OpenAPI) enabled, you can usually access it from a browser by trying one of these common URLs.

  • Create Web API Project-   dotnet new webapi -o api

    -new means to create a new project OR to create file template 
    -Create New ASP.NET Core Empty Web Application./ new Web API
    -o meansOutput Directory.creating a project in a specific folder


  • then cd api

  • Install the Swagger Package - dotnet add package Swashbuckle.AspNetCore

  • Configure the Swagger in to Program.cs 

var builder = WebApplication.CreateBuilder(args);

// Add Services
builder.Services.AddControllers();

// Swagger Services
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

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

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();

  • Runt the project- dotnet run

  • Open this in browserhttps://localhost:5001/swagger

Extensions for VS Code to work with ASP.NET Core Web API features

  • C# Dev Kit (Microsoft)
  • C# (Microsoft)
  • .NET Install Tool (Microsoft)

after installing these three extensions u will get ASP.NET Core Web API features Development Features