All examples

ASP.NET Core Web API, Copilot instructions

The ASP.NET Core Web API rules as GitHub Copilot repository instructions: same content.

Composed from the aspnet-web-api rules pack. Same file from the CLI: aibysitter init --packs aspnet-web-api --format copilot

Written for this site, CC0, scored by this linter, not tested against any agent.

File
copilot-instructions.md, 38 lines
Format
Copilot instructions
Save as
.github/copilot-instructions.md
Category
.NET
Tags
License
CC0 1.0, public domain. No attribution needed.

Download copilot-instructions.md Lint a copy

Aibysitter lint score

100 / 100 — A

Ruleset v4

No deductions.

Badge

Aibysitter lint score: A 100

Markdown for a README:

[![Aibysitter lint score: A 100](https://aibysitting.net/gallery/aspnet-web-api-copilot/badge.svg)](https://aibysitting.net/Gallery/aspnet-web-api-copilot)

copilot-instructions.md

View rendered

  1. # ASP.NET Core web API
  2. ASP.NET Core minimal APIs on .NET 10. PostgreSQL through EF Core and Npgsql. OpenAPI document generated at runtime.
  3. ## Commands
  4. - Build: `dotnet build -warnaserror`
  5. - Test: `dotnet test`
  6. - Run: `dotnet run --project src/<App>.Api` (listens on `http://localhost:5080`)
  7. - OpenAPI document: `GET /openapi/v1.json` while the API is running
  8. ## Endpoints
  9. - Group endpoints by resource in `src/<App>.Api/Endpoints/<Resource>Endpoints.cs` with a `Map<Resource>Endpoints` extension method.
  10. - Request and response types are records in `Contracts/`. Entities never leave the data layer.
  11. - Return `TypedResults` (`Ok`, `Created`, `NotFound`, `ValidationProblem`) and declare them in the handler's return type.
  12. - Validation failures return 400 with `ValidationProblem` and one error per field.
  13. - Unknown IDs return 404 with an empty body.
  14. - Routes are lowercase plural nouns: `/items`, `/items/{id}`, `/items/{id}/movements`.
  15. ## Errors
  16. - Unhandled exceptions become RFC 9457 problem details through `app.UseExceptionHandler()`. Handlers do not catch exceptions to return 500 themselves.
  17. - Optimistic-concurrency failures throw `ConflictException`. The exception handler maps it to 409.
  18. ## Data
  19. - `<App>DbContext` lives in `src/<App>.Data`.
  20. - Bulk changes use `ExecuteUpdateAsync` and `ExecuteDeleteAsync`.
  21. ## Authorization
  22. - Every endpoint requires a policy: `.RequireAuthorization(Policies.Read)` or `.RequireAuthorization(Policies.Write)`.
  23. - `/health` is the only endpoint with `AllowAnonymous`.
  24. ## Tests
  25. - Integration tests in `tests/<App>.Api.Tests` use `WebApplicationFactory<Program>` and a Testcontainers PostgreSQL instance.
  26. - Each new endpoint gets four tests: success, 400 on invalid input, 404 on an unknown ID, 403 without the required policy.
  27. - Test names follow `Method_Condition_Result`.
  28. ## Pull requests
  29. - One endpoint or one bug fix per PR.
  30. - Add a line to `CHANGELOG.md` under the Unreleased heading.