Smallest Minimal Web API in .NET?
Here’s a fun puzzle my colleague Craig Bossie asked me some time ago.
What is the smallest C# .NET 6/7 Web API application that returns a valid HTTP response? Small means the fewest number C# code characters.
Rules -
- It must respond with valid JSON, and include a header with
Content-Type: application/json
. - No changes to the .csproj file.
- No additional NuGet packages or dlls allowed.
You can check the headers by using the dev tools in your browser, Fiddler, Postman, curl (curl -i
), wget, etc.
Suggestion, start from dotnet new web
, and go from there.
My answer, 54 characters, is below. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
var x=WebApplication.Create();x.Map("",()=>1);x.Run();