controllers

A guide to ASP.NET Core controllers, which receive web requests and return API responses.

In plain words
What is it for?
Use it when creating or changing endpoints for reading, creating, updating, or deleting resources.
Why use it?
It keeps routes, HTTP methods, response types, and status codes predictable across the application.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/goranerhartic/cursor-development-rules/controllers
Clone the repo
git clone --depth 1 https://github.com/GoranErhartic/cursor-development-rules

Made for: Cursor.

Per session 16 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 492 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00016 $0.00492
Opus 5 $0.00008 $0.00246
Sonnet 5 $0.00003 $0.00098
Haiku 4.5 $0.00002 $0.00049

Measured 2d ago against content hash d61f509f9127, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

controllers scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/languages/csharp/controllers.mdc · 71 lines

What it actually says

API Controller Conventions

Controller Setup

[ApiController]
[Route("api/[controller]")]
[Produces("application/json")]
public class UsersController : ControllerBase
  • ALWAYS use [ApiController] attribute
  • ALWAYS inherit from ControllerBase (not Controller)
  • Use [Route("api/[controller]")] for consistent routing

HTTP Methods & Status Codes

Operation Method Success Error
Get single GET 200 OK / 404 Not Found
Get list GET 200 OK (empty array if none)
Create POST 201 Created 400 Bad Request
Update PUT 200 OK / 204 No Content 404 Not Found
Partial PATCH 200 OK 404 Not Found
Delete DELETE 204 No Content 404 Not Found

Return Types

// Single item
[HttpGet("{id:guid}")]
public async Task<ActionResult<UserDto>> GetById(Guid id)
{
    var result = await _mediator.Send(new GetUserQuery(id));
    return result.Match<ActionResult<UserDto>>(
        success => Ok(success),
        notFound => NotFound());
}

// Created
[HttpPost]
public async Task<ActionResult<UserDto>> Create(CreateUserCommand command)
{
    var result = await _mediator.Send(command);
    return CreatedAtAction(nameof(GetById), new { id = result.Id }, result);
}

Conventions

  • Use Guid for IDs, constrain routes: {id:guid}
  • Return ActionResult<T> for type safety
  • Use [FromBody], [FromQuery], [FromRoute] explicitly
  • Validate via FluentValidation pipeline behavior, not in controllers
  • Return ProblemDetails for errors (see error-handling.mdc)

API Versioning

[ApiController]
[Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")]
public class UsersController : ControllerBase

See also: validation.mdc, error-handling.mdc

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 71 lines · 16 tokens per session scan A d61f509f9127

Subscribe to this mod's changes

controllers is a cursor rule published in the GitHub repository GoranErhartic/cursor-development-rules (19 stars, last pushed 6mo ago), licensed MIT. It adds 16 tokens to every session and 492 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.