Skip to content

Base Web API Project Template

You can find the official source for the template here: GitHub – Base Web API Template


Overview

A minimal .NET Web API host with JWT auth, Swagger, Serilog, and the Domain Services infrastructure wired up. It has no domain-specific code — you add packages and register services inside a designated #region in Program.cs.


Adding Services

The intended place for adding your own Web APIs, providers, and repository configurations is here:

#region Install Web APIs and providers and configure more services here.
// https://developerdoc-mike-platform-prod.eu.mike-cloud.com/domain_services/how-to/#configuration-in-code
#endregion

For instructions and examples on injecting connections and repositories, see: Connections Project Template


Configuration

The main configuration file is appsettings.json. Key sections include:

  • AppConfiguration – General server settings (e.g., HSTS).
  • Tokens – JWT issuer, audience, and RSA public key.
  • Swagger – API documentation title, description, and specification name.

Example appsettings.json:

{
  "AppConfiguration": {
    "HstsMaxAgeInDays": 1
  },
  "Tokens": {
    "Issuer": "dhigroup.com",
    "Audience": "dhigroup.com",
    "PublicRSAKey": "[env:PublicRSAKey]"
  },
  "Swagger": {
    "SpecificationName": "MyApplicationOpenAPISpecification",
    "DocumentName": "MyApplicationWebAPI",
    "DocumentTitle": "My Application Web API",
    "DocumentDescription": "[AppData]SwaggerInfo.md"
  }
}

Tip: Use [env:...] placeholders for sensitive keys like PublicRSAKey.


Running the Base Web API

Requirements

  • .NET SDK — check the template on GitHub for the current target framework
  • Any required provider/domain NuGet packages

Steps

  1. Clone the template.
  2. Install the Domain Services packages you need, for example:

    dotnet add package DHI.Services.TimeSeries.WebApi
    dotnet add package DHI.Services.PostgreSQL
    
  3. Add service registration in the designated #region.

  4. Update appsettings.json with your JWT keys, CORS, and Swagger info.
  5. Run:

    dotnet run
    
  6. Access Swagger UI at:

    http://localhost:5000/swagger
    

Security Notes

  • Store RSA keys securely, don’t commit production keys in source control.
  • Keep ClockSkew = TimeSpan.Zero if you want strict token validation.
  • Use HTTPS in production (already enforced via HSTS).