router-patterns

A set of routing patterns for the Koa application framework. It explains URL paths, HTTP methods, request validation, middleware, and the request context handlers use.

In plain words
What is it for?
Defining API endpoints, adding dynamic path parameters, accepting specific HTTP methods, validating URL and request data, and writing route handlers.
Why use it?
It helps keep API routes predictable and ensures that parameters and request data are checked before handlers process them. Clear patterns also make routes easier to maintain.

Cursor rule for Codex

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/axiosleo/node-koapp/router-patterns
Clone the repo
git clone --depth 1 https://github.com/AxiosLeo/node-koapp

Made for: Codex.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 417 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.00417
Opus 5 $0.00000 $0.00209
Sonnet 5 $0.00000 $0.00083
Haiku 4.5 $0.00000 $0.00042

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

Security

Grade A, and why

router-patterns 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 yesterday.

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.

.agents/rules/router-patterns.mdc · 63 lines

What it actually says

Router Patterns and Best Practices

Router Structure

Routers are defined using the Router class:

const router = new Router("/api/v1", {
  method: "any", // GET, POST, PUT, DELETE, or "any"
  handlers: [handlerFunction],
  middlewares: [middlewareFunction],
  validators: {
    params: { id: "required|integer" },
    query: { name: "required|string" },
    body: { age: "required|integer" },
  },
});

Path Parameters

Use {:paramName} syntax for dynamic path segments:

  • /users/{:id} - Single parameter
  • /users/{:id}/posts/{:postId} - Multiple parameters

HTTP Methods

  • Use specific methods: router.get(), router.post(), router.put(), router.delete()
  • Use router.push(method, path, handler) for custom methods
  • Use method: "any" to accept all HTTP methods

Validation

Request validation uses validatorjs rules:

  • params - URL path parameters
  • query - Query string parameters
  • body - Request body data

Handler Functions

Handler functions receive a context object with:

  • context.koa - Koa context
  • context.params - Path parameters
  • context.query - Query parameters
  • context.body - Request body
  • context.method - HTTP method

Response Methods

Use response helpers from src/response.js:

  • success(data) - 200 OK response
  • failed(data, code, status) - Error response
  • result(data, status, headers) - Custom response
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. yesterday First seen · 63 lines · 417 tokens per session scan A 2ec4b6aef0b1

Subscribe to this mod's changes

router-patterns is a cursor rule published in the GitHub repository AxiosLeo/node-koapp (129 stars, last pushed 18d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 417 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-30.