spring-boot-controller

Rules for Spring Boot controllers, which receive web requests and return web responses. They cover URL mappings, HTTP status codes, validation, response objects, and the boundary between controllers and business services.

In plain words
What is it for?
Use them when creating or reviewing REST endpoints and page-flow controllers for GET, POST, PUT, DELETE, and PATCH operations.
Why use it?
They keep web endpoints consistent and prevent controllers from becoming overloaded with business logic or returning unclear responses.

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/lsampaioweb/ai-instructions/spring-boot-controller
Clone the repo
git clone --depth 1 https://github.com/lsampaioweb/ai-instructions

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 476 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.00000 $0.00476
Opus 5 $0.00000 $0.00238
Sonnet 5 $0.00000 $0.00095
Haiku 4.5 $0.00000 $0.00048

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

Security

Grade A, and why

spring-boot-controller 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/spring-boot-controller.mdc · 38 lines

How it starts

The opening of the file, as written. The whole thing — 38 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Spring Boot Controller Engine

Naming Conventions

  • Name controller classes with the *Controller suffix (e.g., HolidayController, AccountController).
  • Use descriptive resource names in controller class identifiers (never ApiController or WebController).
  • Annotate REST API controllers with @RestController.
  • Annotate page-flow controllers with @Controller.

Rules

  • Use class-level @RequestMapping for every controller.
  • Use method-level HTTP verb annotations (@GetMapping, @PostMapping, @PutMapping, @DeleteMapping, @PatchMapping) for each operation.
  • Keep controller logic thin and delegate business rules to services.
  • Return ResponseEntity with a typed *Response DTO for all REST endpoints.
  • Include a Location response header on HTTP 201 responses pointing to the created resource URL.
  • Build the Location URI using UriComponentsBuilder injected as a method parameter in the POST handler.
  • Return HTTP 200 OK for GET and PUT operations.
  • Return HTTP 200 with an empty collection for GET collection endpoints that produce no results.
  • Return HTTP 201 Created with the created resource body for POST operations.
  • Return HTTP 204 No Content for DELETE operations.
  • Return HTTP 404 when a DELETE operation targets a non-existent resource.
  • Return HTTP 404 when a single-resource GET finds no matching resource.
  • Return explicit view names for page-flow controller methods.
  • Apply @Valid to all @RequestBody parameters.
  • Apply @Positive to numeric @PathVariable resource-identifier parameters.
  • Map Optional<T> service returns via .map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()).

Safety Guards

  • Never call Optional.get() directly on a service-returned Optional<T>.
  • Never mix @RestController and page-rendering responsibilities in the same controller class.
  • Never mix unrelated resource routes in one controller class.
  • Never expose internal exception details in controller responses.
  • Never use @RequestBody on GET or DELETE methods.

Read the full file on GitHub · 38 lines

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 · 38 lines · 0 tokens per session scan A 005d508cdd85

Subscribe to this mod's changes

spring-boot-controller is a cursor rule published in the GitHub repository lsampaioweb/ai-instructions (1 stars, last pushed 10d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 476 tokens. 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-31.