axiosleo/node-koapp/koapp-router
Claude Code and agent skill by axiosleo/node-koapp
- community
Checking that the SKILL.md file is still in the repository.
Define routes, path parameters, validators, and nested routers with the @axiosleo/koapp Router class. Use when declaring HTTP/WebSocket/TCP routes in koapp, adding path params like /users/{:id}, composing nested routers, attaching per-route middlewares or after-handlers, validating params/query/body with validatorjs rules, or using shortcut helpers (get/post/put/patch/delete/any).
Install
npx vskill@latest install axiosleo/node-koapp/koapp-routerSKILL.md
@axiosleo/koapp Router
Source: `src/router.js`.
Router is the single route-definition primitive for all three application types (KoaApplication, SocketApplication, WebSocketApplication). A router can be flat or a tree of sub-routers, and it carries middlewares, handlers, after-handlers, and validators.
Constructor
| Arg | Type | Default | Notes | |
|---|---|---|---|---|
prefix | string | '' | Path prefix like /api/v1 or /users/{:id} | |
options.method | string | '' | HTTP method. Use 'any' for all methods. Empty string disables the route | |
options.handlers | Function[] | [] | Async handler functions async (context) => { ... } | |
options.middlewares | Function[] | [] | Run before handlers | |
options.afters | Function[] | [] | Run after handlers (even on thrown response) | |
options.validators | object | {} | { params, query, body } - each { rules, messages? } |
Any unknown keys on options are kept on the router instance as-is.
Path params
Use {:name} for path parameters. Legacy :name also works but {:name} is preferred:
Wildcards:
/*- matches one segment (captured asparams.<next>if named)/**- matches one segment without capture/***- matches any remaining path, ideal for fallback handlers
HTTP method shortcuts
Each method shortcut creates a nested sub-router:
Under the hood every shortcut delegates to router.push(method, prefix, handler, validator).
Custom methods
The framework uppercases and stores the method; match it by sending the same method string.
Combining multiple methods
Nested routers
router.add(...subrouters) attaches other Router instances. If the first argument is a string prefix, sub-routers are added under it:
The helper router.new(prefix, options) creates and mounts a sub-router in one call:
Middlewares and afters
- Middlewares inherit down the tree (children + grandchildren see them)
- Afters also inherit and run after any handler in the subtree
- Throwing inside a handler still runs afters
Request validation
Validation uses validatorjs rules.
On failure the framework throws HttpError(400, <first-error-message>) which the workflow converts into a 400 response.
Common validatorjs rules: required, string, integer, numeric, email, url, min:N, max:N, in:a,b,c, regex:/pattern/, boolean, array.
The catch-all fallback
To handle anything that did not match:
'/***' matches any remaining path. The framework falls back to the deepest matching /*** route when no exact match is found.
Method resolution order
For a request PUT /users/42:
- Walk the router tree by path segments, preferring static matches over
*/**/*** - When multiple candidates remain, prefer the one whose
methodlist includes the request method (orANY) - If nothing matches, follow the nearest
/***fallback - If even that misses, the framework lets the next Koa middleware run (typically 404)
Common pitfalls
- Leaving
method: ''(or unset) on arouter.pushcreates a route that
matches no HTTP method - requests fall through to fallback handlers. Always use 'any' or a concrete method unless you know you want this.
new Router('/')andnew Router('')behave differently; prefernull
or '' for the root.
- Path params must use
{:name}inside route segments -{:name}**must
be the entire segment**, not a substring (/a-{:x} does not work).
- Validators bubble with the router; nested routers inherit parent middlewares
and afters, so avoid double-registering auth middlewares.
See also
- Richer, copy-paste examples: examples.md
- Building a complete HTTP server around the router: koapp-apps
- Sending responses from handlers: koapp-response
- Typed contexts and Router generics in TypeScript: koapp-typescript
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingassets/skills/koapp-router/SKILL.md
Popularity
- Repository stars
- 135
- Repository forks
- 12
- Repository npm downloads, 7 days
- 322
- 7-day trend score
- 39
Stars and forks are for the whole GitHub repository, not this skill alone. Downloads are for the repository's npm package. Refreshed 4 Jun 2026, 5 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/axiosleo/node-koapp/koapp-router)