Skip to content

Deadvi5/MinimalApiDemo

Repository files navigation

Todo REST MINIMAL API

Todo REST API samples using ASP.NET Core minimal APIs. It showcases:

  • Using EntityFramework and PostgreSQL for data access
  • JWT authentication
  • OpenAPI support
  • API Versioning
  • Writing tests for your REST API
  • HTTP2 ready

Prerequisites

.NET

  1. Install .NET 7

Database

  1. PostgreSQL intance: browse Docker folder and run
    • docker-start.bat for Windows
    • docker-start.sh for Linux/MacOS
  2. Install the dotnet-ef tool: dotnet tool install dotnet-ef -g
  3. Navigate to the TodoApi folder and run dotnet ef database update to create the database.
  4. Learn more about dotnet-ef

Authentication

  1. Run dotnet user-jwts create to create a JWT token for your user and dotnet user-jwts create -n admin --role admin to create an admin user.
  2. You should be able to use these tokens to make authenticated requests to the endpoint.
  3. Learn more about user-jwts

Optional

OpenTelemetry

TodoApi uses OpenTelemetry to collect logs, metrics and spans. If you wish to view the collected telemetry, follow the steps below.

Metrics

  1. Prometheus is included in Docker Compose
  2. Open Prometheus in your browser
  3. Query the collected metrics

Distributed trace

  1. Jaeger is included in Docker Compose
  2. Uncomment .AddOtlpExporter below builder.Services.AddOpenTelemetryTracing, in the TodoApi/OpenTelemetryExtensions.cs file
  3. Open Jaeger in your browser
  4. View the collected spans

Load Testing

K6

  1. Install k6
  2. Browse LoadTesting folder
  3. Execute load test from terminal with k6 run script.js