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-oapi
-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 Servicesbuilder.Services.AddControllers();// Swagger Servicesbuilder.Services.AddEndpointsApiExplorer();builder.Services.AddSwaggerGen();var app = builder.Build();// Swagger Middlewareif (app.Environment.IsDevelopment()){app.UseSwagger();app.UseSwaggerUI();}app.UseHttpsRedirection();app.UseAuthorization();app.MapControllers();app.Run();
- Runt the project- dotnet run
- Open this in browser- https://localhost:5001/swagger
- C# Dev Kit (Microsoft)
- C# (Microsoft)
- .NET Install Tool (Microsoft)