Skip to content

Instantly share code, notes, and snippets.

@IEvangelist
Last active February 1, 2023 19:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save IEvangelist/5c5706221fed67fe1fb87f98b49b4ff6 to your computer and use it in GitHub Desktop.
Save IEvangelist/5c5706221fed67fe1fb87f98b49b4ff6 to your computer and use it in GitHub Desktop.

This is a sample app, trying to demonstrate the smallest ASP.NET Core Minimal API, a "Hello World!" example. The Program.cs* is only three lines of code.

Program.cs:

var app = WebApplication.CreateBuilder(args).Build();
app.MapGet("/", () => "Hello World!");
app.Run();
Expand to see *Sample.cspoj* and *launchSettings.json* files

Sample.csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
</Project>

Properties/launchSettings.json:

{
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "profiles": {
    "http": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "http://localhost:5029",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "https": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:7263;http://localhost:5029",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

Note The appsettings.json file is optional

image

Run the app:

image

@IEvangelist
Copy link
Author

Hi @kkgthb - I've updated this now to .NET 7 and minimal APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment