3 lines of code for an ASP.NET Web API

Okay, this is admittedly a bit of a frivolous post. That said, with just these 3 lines of code, you will have a REST API up and running.

var app = WebApplication.Create();
app.MapGet("/", () => $"Running @ {DateTime.UtcNow}");
await app.RunAsync();

Line 1 instantiates your web app instance, the 2nd line adds your one endpoint, and the last one starts the web app (http listener).

Leave a Reply