This is a Todo application that features:
- Todo.Web - An ASP.NET Core hosted Blazor WASM front end application
- TodoApi - An ASP.NET Core REST API backend using minimal APIs
It showcases:
- Blazor WebAssembly
- Minimal APIs
- Using EntityFramework and SQLite for data access
- OpenAPI
- User management with ASP.NET Core Identity
- Cookie authentication
- JWT authentication
- Proxying requests from the front end application server using YARP's IHttpForwarder
- Rate Limiting
- Writing integration tests for your REST API
- Install the dotnet-ef tool:
dotnet tool install dotnet-ef -g
- Navigate to the
TodoApi
folder and rundotnet ef database update
to create the database. - Learn more about dotnet-ef
To run the application, run both the Todo.Web/Server and TodoApi. Below are different ways to run both applications:
-
Visual Studio - Setup multiple startup projects by right clicking on the solution and selecting Properties. Select
TodoApi
andTodo.Web.Server
as startup projects. -
Visual Studio Code - Open up 2 terminal windows, one in Todo.Web.Server and the other in TodoApi run:
dotnet watch run -lp https
This will run both applications with the
https
profile. -
Tye - Install the global tool using the following command:
dotnet tool install --global Microsoft.Tye --version 0.11.0-alpha.22111.1
Run
tye run
in the repository root and navigate to the tye dashboard (usually https://localhost:8080) to see both applications running.
The Todo REST API can run standalone as well. You can run the TodoApi project and make requests to various endpoints using the Swagger UI (or a client of your choice):
Before executing any requests, you need to create a user and get an auth token.
-
To create a new user, run the application and POST a JSON payload to
/users
endpoint:{ "username": "myuser", "password": "<put a password here>" }
-
To get a token for the above user run
dotnet user-jwts
to create a JWT token with the same user name specified above e.g:dotnet user-jwts create -n myuser
-
You should be able to use this token to make authenticated requests to the todo endpoints.
-
Learn more about user-jwts
TodoApi uses OpenTelemetry to collect logs, metrics and spans.
If you wish to view the collected telemetry, follow the steps below.
- Run Prometheus with Docker:
docker run -d -p 9090:9090 --name prometheus -v $PWD/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
- Open Prometheus in your browser
- Query the collected metrics
- Uncomment
.AddOtlpExporter
belowbuilder.Services.AddOpenTelemetryTracing
, in theTodoApi/OpenTelemetryExtensions.cs
file - Run Jaeger with Docker:
docker run -d --name jaeger -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 -e COLLECTOR_OTLP_ENABLED=true -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 16686:16686 -p 4317:4317 -p 4318:4318 -p 14250:14250 -p 14268:14268 -p 14269:14269 -p 9411:9411 jaegertracing/all-in-one:latest
- Open Jaeger in your browser
- View the collected spans
- Uncomment
.AddOtlpExporter
belowbuilder.Logging.AddOpenTelemetry
, in theTodoApi/Extensions/OpenTelemetryExtensions.cs
file - Find a Vendor that supports OpenTelemetry-based logging.
Vendor support for OpenTelemetry-based logging is currently very limited.