К основному содержанию
правило официальный · GitHub

aspnet-rest-apis — правило для GitHub Copilot: суть и настройка

Направляет GitHub Copilot при создании REST API на ASP.NET Core 10, сопоставляя контроллеры и Minimal API. Применяется к файлам *.cs и *.json.

Установить в GitHub Copilot · Вручную: положить файлы Все способы и платформы ↓
.github/instructions/aspnet-rest-apis.instructions.md
Открыть на GitHub

Что делает aspnet-rest-apis

Правило задаёт стандарты разработки REST API на ASP.NET Core 10. Оно заставляет ассистента объяснять архитектурные решения и сравнивать два подхода: классические контроллеры с атрибутной маршрутизацией и Minimal API. Copilot даёт разбор кода, проектирует маршруты ресурсов и помогает выстроить структуру проекта через разделение на слои или подход Feature Folders.

В инструкцию заложены конкретные паттерны: доступ к данным через Entity Framework Core, миграции и авторизация через Microsoft Entra ID либо JWT Bearer. Для валидации предлагаются Data Annotations и FluentValidation, а для ошибок — стандарт Problem Details (RFC 9457). Также правило описывает контейнеризацию вызовом dotnet publish --os linux --arch x64 -p:PublishProfile=DefaultContainer, метрики для Application Insights и логирование через Serilog.

Фронтматтер ограничивает применение правила масками **/*.cs и **/*.json. Поэтому Copilot не станет подмешивать эти рекомендации при редактировании сценариев CI/CD или файлов Dockerfile, если они не завязаны на JSON.

Какие задачи решает

  • Сравнить контроллеры и Minimal API при проектировании эндпоинтов на ASP.NET Core 10
  • Настроить структурированное логирование через Serilog и телеметрию в Application Insights
  • Реализовать единый формат ошибок по стандарту RFC 9457 Problem Details
  • Собрать контейнер приложения без Dockerfile командой dotnet publish

Примеры запросов агенту

  • Спроектируй Minimal API для каталога товаров с валидацией через FluentValidation и возвратом Problem Details.
  • Покажи, как переписать контроллер с JWT-авторизацией на эндпоинты Minimal API в ASP.NET Core 10.
  • Настрой интеграционные тесты для эндпоинтов авторизации с моками зависимостей.

Как установить aspnet-rest-apis

Вручную: положить файлы

.github/instructions/aspnet-rest-apis.instructions.md

Поле applyTo задаёт, к каким файлам применять

По шагам, с командами для каждой платформы: AGENTS.md и CLAUDE.md: что это, кто читает и какой выбрать

Вопросы о aspnet-rest-apis

Как установить aspnet-rest-apis в GitHub Copilot?

Создайте файл по пути .github/instructions/aspnet-rest-apis.instructions.md в корне репозитория и сохраните в него текст правила.

Какую версию .NET использует правило aspnet-rest-apis?

Инструкции ориентированы на ASP.NET Core 10 и охватывают встроенные функции платформы, включая контейнеризацию без внешнего Dockerfile.

К каким файлам проекта применяется это правило?

Правило автоматически активируется для файлов с масками **/*.cs и **/*.json.

Исходный текст

aspnet-rest-apis.instructions.md · MIT
---
description: 'Guidelines for building REST APIs with ASP.NET'
applyTo: '**/*.cs, **/*.json'
---

# ASP.NET REST API Development

## Instruction
- Guide users through building their first REST API using ASP.NET Core 10.
- Explain both traditional Web API controllers and the newer Minimal API approach.
- Provide educational context for each implementation decision to help users understand the underlying concepts.
- Emphasize best practices for API design, testing, documentation, and deployment.
- Focus on providing explanations alongside code examples rather than just implementing features.

## API Design Fundamentals

- Explain REST architectural principles and how they apply to ASP.NET Core APIs.
- Guide users in designing meaningful resource-oriented URLs and appropriate HTTP verb usage.
- Demonstrate the difference between traditional controller-based APIs and Minimal APIs.
- Explain status codes, content negotiation, and response formatting in the context of REST.
- Help users understand when to choose Controllers vs. Minimal APIs based on project requirements.

## Project Setup and Structure

- Guide users through creating a new ASP.NET Core 10 Web API project with the appropriate templates.
- Explain the purpose of each generated file and folder to build understanding of the project structure.
- Demonstrate how to organize code using feature folders or domain-driven design principles.
- Show proper separation of concerns with models, services, and data access layers.
- Explain the Program.cs and configuration system in ASP.NET Core 10 including environment-specific settings.

## Building Controller-Based APIs

- Guide the creation of RESTful controllers with proper resource naming and HTTP verb implementation.
- Explain attribute routing and its advantages over conventional routing.
- Demonstrate model binding, validation, and the role of [ApiController] attribute.
- Show how dependency injection works within controllers.
- Explain action return types (IActionResult, ActionResult<T>, specific return types) and when to use each.

## Implementing Minimal APIs

- Guide users through implementing the same endpoints using the Minimal API syntax.
- Explain the endpoint routing system and how to organize route groups.
- Demonstrate parameter binding, validation, and dependency injection in Minimal APIs.
- Show how to structure larger Minimal API applications to maintain readability.
- Compare and contrast with controller-based approach to help users understand the differences.

## Data Access Patterns

- Guide the implementation of a data access layer using Entity Framework Core.
- Explain different options (SQL Server, SQLite, In-Memory) for development and production.
- Demonstrate repository pattern implementation and when it's beneficial.
- Show how to implement database migrations and data seeding.
- Explain efficient query patterns to avoid common performance issues.

## Authentication and Authorization

- Guide users through implementing authentication using JWT Bearer tokens.
- Explain OAuth 2.0 and OpenID Connect concepts as they relate to ASP.NET Core.
- Show how to implement role-based and policy-based authorization.
- Demonstrate integration with Microsoft Entra ID (formerly Azure AD).
- Explain how to secure both controller-based and Minimal APIs consistently.

## Validation and Error Handling

- Guide the implementation of model validation using data annotations and FluentValidation.
- Explain the validation pipeline and how to customize validation responses.
- Demonstrate a global exception handling strategy using middleware.
- Show how to create consistent error responses across the API.
- Explain problem details (RFC 9457) implementation for standardized error responses.

## API Versioning and Documentation

- Guide users through implementing and explaining API versioning strategies.
- Demonstrate Swagger/OpenAPI implementation with proper documentation.
- Show how to document endpoints, parameters, responses, and authentication.
- Explain versioning in both controller-based and Minimal APIs.
- Guide users on creating meaningful API documentation that helps consumers.

## Logging and Monitoring

- Guide the implementation of structured logging using Serilog or other providers.
- Explain the logging levels and when to use each.
- Demonstrate integration with Application Insights for telemetry collection.
- Show how to implement custom telemetry and correlation IDs for request tracking.
- Explain how to monitor API performance, errors, and usage patterns.

## Testing REST APIs

- Guide users through creating unit tests for controllers, Minimal API endpoints, and services.
- Explain integration testing approaches for API endpoints.
- Demonstrate how to mock dependencies for effective testing.
- Show how to test authentication and authorization logic.
- Explain test-driven development principles as applied to API development.

## Performance Optimization

- Guide users on implementing caching strategies (in-memory, distributed, response caching).
- Explain asynchronous programming patterns and why they matter for API performance.
- Demonstrate pagination, filtering, and sorting for large data sets.
- Show how to implement compression and other performance optimizations.
- Explain how to measure and benchmark API performance.

## Deployment and DevOps

- Guide users through containerizing their API using .NET's built-in container support (`dotnet publish --os linux --arch x64 -p:PublishProfile=DefaultContainer`).
- Explain the differences between manual Dockerfile creation and .NET's container publishing features.
- Explain CI/CD pipelines for ASP.NET Core applications.
- Demonstrate deployment to Azure App Service, Azure Container Apps, or other hosting options.
- Show how to implement health checks and readiness probes.
- Explain environment-specific configurations for different deployment stages.

© github · MIT · github/awesome-copilot

Похожие правила IDE

Все правила IDE по теме «Бэкенд и API» →

Из того же набора732

Весь набор →
azure-devops-pipelines Правило задаёт практики для Azure DevOps Pipeline YAML: структура, тесты, безопасность и деплой. Пригодится для проверки и ведения pipeline-файлов. ★ 40 418звёзд репо aws-appsync Задаёт правила разработки обработчиков AWS AppSync Event API на рантайме APPSYNC_JS. Помогает писать код с учётом строгих ограничений среды без промисов и стандартных блоков ошибок. ★ 40 418звёзд репо attester-verify-packages Проверяет имена пакетов и символов PyPI и npm через attester.dev до установки или импорта. Нужен для защиты от выдуманных зависимостей. ★ 40 418звёзд репо astro Правило задаёт Copilot стандарты разработки на Astro 7: островная архитектура, Content Layer API, TypeScript и серверный рендеринг по умолчанию. ★ 40 418звёзд репо arch-linux Правило задаёт рекомендации для инструкций и скриптов по Arch Linux: от обновления через pacman до проверки служб. Пригодится, когда Copilot помогает администрировать систему. ★ 40 418звёзд репо apex Правило задаёт Copilot стиль кода Apex: массовые операции, имена классов и методов, проверка прав доступа. Пригодится, если вы пишете триггеры и классы на платформе Salesforce. ★ 40 418звёзд репо ansible Задаёт стандарты написания плейбуков Ansible: правила именования задач, формат коллекций FQCN, разделение секретов в Ansible Vault и проверки через ansible-lint. ★ 40 418звёзд репо ai-prompt-engineering-safety-best-practices Правило помогает формулировать запросы к ИИ с ясным контекстом, ограничениями и требованиями к формату. Оно также предлагает учитывать безопасность и предвзятость при создании и проверке промптов. ★ 40 418звёзд репо

Спонсоры проекта

Компании, которые помогают держать аналитику открытой