Skip to content

Latest commit

 

History

History
82 lines (57 loc) · 5.83 KB

NUGET.md

File metadata and controls

82 lines (57 loc) · 5.83 KB

Clean Minimal API

A dotnet new template for an HTTP API using ASP.NET Core Minimal APIs in .NET 10, built with a streamlined Clean Architecture. All the layers you need, none of the ceremony you don't.

It's one of five Lean Mean Clean Apps templates, for Minimal APIs, Model Context Protocol, GraphQL, Web API controllers and AWS Lambda. They share the same Application and Infrastructure layers and differ only in how they face the world. The full docs live at leanmeanclean.dev/minimalapi.

Template Presentation Package Docs
Clean Minimal API ASP.NET Core Minimal APIs, you are here CleanMinimalApi.Template Docs
Clean Model Context Protocol Model Context Protocol server CleanModelContextProtocol.Template Docs
Clean GraphQL API GraphQL with Hot Chocolate CleanGraphQLApi.Template Docs
Clean Web API ASP.NET Core controllers CleanWebApi.Template Docs
Clean Lambda Function AWS Lambda CleanLambdaFunction.Template Docs

Get started

You need the .NET 10 SDK. Docker is optional, but it's the quickest way to see it running.

# Install the template
dotnet new install CleanMinimalApi.Template

# Create a solution
dotnet new cleanminimalapi --name WorksOnMyMachine.Movies --authorName "Your Name"
cd WorksOnMyMachine.Movies

cleanminimal works too, for anyone who'd rather not type cleanminimalapi every time, and so do lmca-minimalapi and leanmeancleanapps-minimalapi. dotnet new search leanmeanclean lists the whole family.

Option Short Default What it does
--name -n The folder's name Names the solution and its root namespace
--authorName -an Stephen Walsh Puts your name on the assembly instead of ours
--include-auth Off Adds JWT bearer token authentication. Leave it out and the API has no auth code at all
--authority -iss Empty Your OAuth authorization server. Required with --include-auth
--audience -aud Empty The audience tokens must be issued for, usually the API's own URL. Only used with --include-auth
--no-restore Off Skips the package restore that normally runs once the solution is created

Rather click than type? Visual Studio and Rider show the same options in their new project dialogs. They always show the authority and audience fields, but only use them when Include authentication is ticked. In the terminal, dotnet new cleanminimalapi --help lists them all.

Run it

# Build the image and start it with sample data, plus a collector and the Aspire dashboard for its telemetry
docker compose up -d --build

# Ask it for a page of movies
curl "http://localhost:7310/api/movies?query=space&limit=2"

# Run the tests while you're here
dotnet test

Then open Scalar at http://localhost:7310/scalar to browse and try every endpoint.

The API is open unless you create it with --include-auth --authority (and usually --audience), and then it asks for a JWT bearer token. Leave --include-auth out and there's no auth code at all.

What's inside

  • Presentation: the HTTP API, with Minimal API endpoints grouped by feature and documented for Scalar from XML comments
  • Application: commands and queries through Mediator, validated by FluentValidation and mapped by Mapperly
  • Infrastructure: Entity Framework Core on SQLite, with optional sample data
  • Tests: xUnit, Shouldly and NSubstitute, each on its own throwaway database
  • Extras: OpenTelemetry traces, metrics and Serilog logs over OTLP, health checks, a Dockerfile that runs as a non-root user, Docker Compose, and a GitHub Actions pipeline that won't let your coverage slip

Releases

A new version lands on the 1st of each month, as long as something changed. No changes, no release. We're not here to pad the download stats.

dotnet new update

More help

Who built this

Built by Stephen Walsh in spare time, with strong coffee and a healthy disregard for pomp and ceremony. If this template saves you some time, sponsoring the work keeps all five templates current and the coffee flowing.