ASP.NET Core Web API Fundamentals

Creating the API and Returning Resources

  • Microsoft.NET.Sdk.Web implicitly includes the Microsoft.AspNetCore.App framework reference, which includes all supported packages by ASP.NET Core and Entity Framework Core.
  • dotnet run --launch-profile <name of the profile to run during the startup of the project>

var builder = WebApplication.CreateBuilder(args); // The webhost to build the web application

// The minimal hosting model for webapis in .NET 6+. Bellow are the set of services to be added to the DI container
builder.Services.AddControllers(); //  This method registers the necessary services for supporting controllers on our container
builder.Services.AddEnpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();
if(app.Environment.IsDevelopment())
{
	app.UseSwagger();
	app.UseSwaggerUI();
}

app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();

app.Run();