ASP.NET Core API Starter in C#

An ASP.NET Core minimal API starter in C# on .NET 8 for .NET developers who want a small web service to rename and extend. It includes grouped endpoints, the options pattern, a health check with uptime, open CORS, xUnit tests and a two-stage Dockerfile.

by Light CloudREST APIs

Features

  • GET / returns message, version and an endpoint list from the Api section of appsettings.json
  • GET /health returns {"status": "healthy"} with a UTC timestamp and uptime in seconds
  • Uptime comes from a singleton created at start-up with TimeProvider, so it counts from app start
  • Endpoints live in a MapRootEndpoints extension class, keeping Program.cs short
  • Override any setting with double underscores, such as Api__Message, without touching the JSON files
  • CORS open to any origin, method and header, so a browser frontend on another domain can call it
  • xUnit tests start the real app in memory with WebApplicationFactory, including a 404 check
  • Two-stage Dockerfile: the .NET 8 SDK image builds, the smaller ASP.NET runtime image runs

Tech stack

What you need

  • Free plan: it runs as a server app, and the Free plan includes 3 server apps
  • To run it locally: the .NET 8 SDK (Docker is optional, for building the image)
  • No API keys: it starts with nothing to configure
  • Optional: Api__Message and Api__Version to change what GET / returns

About

Program.cs binds Kestrel to 0.0.0.0 and the port in PORT, registers ApiInfoOptions and the Uptime service, and maps the endpoints; handlers receive their dependencies as parameters and return anonymous objects that ASP.NET Core writes as JSON. The first thing most people change is CORS: swap AllowAnyOrigin() for WithOrigins(...) with their frontend's address. The repo also ships a .mcp.json for the Light Cloud MCP server, and Light Cloud builds the Dockerfile and redeploys on each push to your copy.

FAQ

How do I add an endpoint to an ASP.NET Core minimal API?

Add a static class in Endpoints/ with a Map...Endpoints extension method, following RootEndpoints.cs, and call it from Program.cs next to app.MapRootEndpoints().

How do I override appsettings.json with environment variables in .NET?

Join the section and key with a double underscore: Api__Message="Hello" dotnet run overrides Api:Message. Environment variables take priority over the JSON files.

How do I add Swagger to a .NET 8 minimal API?

Add the Swashbuckle.AspNetCore package, call builder.Services.AddEndpointsApiExplorer() and builder.Services.AddSwaggerGen(), then app.UseSwagger() and app.UseSwaggerUI(). Swagger UI is then at /swagger.

How do I test an ASP.NET Core API without starting a server?

This starter uses WebApplicationFactory<Program> from Microsoft.AspNetCore.Mvc.Testing, which runs the app in memory and hands the tests an HttpClient. Program.cs ends with public partial class Program so the factory can find it.

Can I host this .NET API without Light Cloud?

Yes. Run the Docker image on any container host, or run dotnet publish DotnetApi.csproj -c Release -o out and start dotnet out/DotnetApi.dll on a server with the ASP.NET Core 8 runtime.

Price
Free
Framework
ASP.NET · .NET
Plan
Free
Updated

Related templates

All rest api starters