15-spring-rest-api-conventions

15-spring-rest-api-conventions is a cursor rule for coding agents from movebrickschi/harness-engineering-mcp. It costs 1,360 tokens per session, scanned A, original, MIT.

A set of coding rules for REST APIs built with Spring Boot, a Java framework for web services. It covers response formats, URL paths, authentication, dependency injection, and error handling.

In plain words
What is it for?
Use it when creating or reviewing Spring Boot controllers and endpoints. It guides how to return data, name URLs, inject services, protect routes, and handle errors.
Why use it?
It keeps API code consistent, so developers and clients know how endpoints behave. It also reduces common mistakes in access checks and request handling.

Cursor rule

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/movebrickschi/harness-engineering-mcp/15-spring-rest-api-conventions
Clone the repo
git clone --depth 1 https://github.com/movebrickschi/harness-engineering-mcp

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for 15-spring-rest-api-conventions

README.md
[![agentmods](https://agentmods.dev/badge/rules/movebrickschi/harness-engineering-mcp/15-spring-rest-api-conventions.svg)](https://agentmods.dev/rules/movebrickschi/harness-engineering-mcp/15-spring-rest-api-conventions)
Your own site
<a href="https://agentmods.dev/rules/movebrickschi/harness-engineering-mcp/15-spring-rest-api-conventions"><img src="https://agentmods.dev/badge/rules/movebrickschi/harness-engineering-mcp/15-spring-rest-api-conventions.svg" alt="Measured on agentmods" height="20"></a>
Per session 1,360 This file is loaded in full into every session.
When invoked 1,360 The same file — it is already loaded in full.
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.01360 $0.01360
Opus 5 $0.00680 $0.00680
Sonnet 5 $0.00272 $0.00272
Haiku 4.5 $0.00136 $0.00136

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

Security

Grade A, and why

15-spring-rest-api-conventions 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 4d 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.

assets/rules/15-spring-rest-api-conventions.mdc · 204 lines

How it starts

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

Spring Boot REST API 编码约定

统一响应格式

所有 Controller 方法必须返回 R<T>,禁止直接返回裸对象或 ResponseEntity

// ✅ 正确
@GetMapping("/{id}")
public R<UserVO> getUser(@PathVariable Long id) {
    return R.ok(userService.findById(id));
}

@DeleteMapping("/{id}")
public R<Void> deleteUser(@PathVariable Long id) {
    userService.delete(id);
    return R.ok();
}

// ❌ 禁止
@GetMapping("/{id}")
public UserVO getUser(@PathVariable Long id) { ... }

@GetMapping("/{id}")
public ResponseEntity<UserVO> getUser(@PathVariable Long id) { ... }

URL 路径规范

前缀 用途 鉴权要求
/api/admin/... 后台管理接口 @PreAuthorize("@authGuard.isSysUser(authentication)")
/api/app/... 前台用户接口 @PreAuthorize("@authGuard.isAppUser(authentication)")@PublicApi

RESTful 风格:

  • 列表:GET /api/admin/user/listGET /api/admin/user/page
  • 详情:GET /api/admin/user/{id}
  • 新增:POST /api/admin/user
  • 修改:PUT /api/admin/user/{id}
  • 删除:DELETE /api/admin/user/{id}

依赖注入

统一使用构造器注入 + Lombok @RequiredArgsConstructor,禁止 @Autowired 字段注入。

// ✅ 正确
@RestController
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;
    private final AuditLogService auditLogService;
}

// ❌ 禁止
@RestController
public class UserController {
    @Autowired
    private UserService userService;
}

权限与认证

后台接口

类级别添加 @PreAuthorize + @SecurityRequirement

@SecurityRequirement(name = "Bearer")
@PreAuthorize("@authGuard.isSysUser(authentication)")
@RestController
@RequestMapping("/api/admin/xxx")
public class AdminXxxController { }

公开接口

无需登录的接口使用 @PublicApi 注解,SecurityConfig 自动放行:

@PublicApi
@GetMapping("/public/list")
public R<List<ItemVO>> publicList() { }

获取当前用户

使用 @AuthenticationPrincipal LoginUser 获取当前登录用户信息:

@PostMapping
public R<Void> create(@RequestBody @Valid CreateDTO dto,
                      @AuthenticationPrincipal LoginUser loginUser) {
    Long userId = loginUser.getUserId();
    // ...
}

Read the full file on GitHub · 204 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. 4d ago First seen · 204 lines · 1,360 tokens per session scan A 9bfffd352e56

Subscribe to this mod's changes

15-spring-rest-api-conventions is a cursor rule published in the GitHub repository movebrickschi/harness-engineering-mcp (2 stars, last pushed 3mo ago), licensed MIT. It adds 1,360 tokens to every session, about $0.0068 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-31.