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 -

  1. It must respond with valid JSON, and include a header with Content-Type: application/json.
  2. No changes to the .csproj file.
  3. 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();

comments powered by Disqus

Related