new-server-route
Skill0 starsChanged 8 months agoMITView on GitHub
Scaffold a Nitro server route (REST endpoint). Use when the user asks to create a REST API endpoint, webhook, file upload handler, OAuth callback, or any non-GraphQL server-side route.
In this repository10 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- design-componentSkill
- new-componentSkill
- new-composableSkill
- new-gql-operationSkill
- new-migrationSkill
- new-quill-fieldSkill
- new-resolverSkill
- new-settings-storeSkill
- new-storeSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 2 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
Place in server/api/ (accessible at /api/[name]) or server/routes/ (accessible at /[name])
- Very specific: line 11
Always validate input with explicit checks — no raw body without validation
- Very specific: line 12
Always protect with requireUserSession(event) unless explicitly public
- Very specific: line 13
Use readBody for POST/PUT, getQuery for GET params, getRouterParam for path params
- Distinctive: line 94
Ask: what HTTP method, what path, what does it do?
- Distinctive: line 97
If it handles file uploads, ask about storage strategy
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Skill: New Server Route
Rules
- File naming sets HTTP method:
[name].get.ts,[name].post.ts,[name].delete.ts - Place in
server/api/(accessible at/api/[name]) orserver/routes/(accessible at/[name]) - Always validate input with explicit checks — no raw
bodywithout validation - Always protect with
requireUserSession(event)unless explicitly public - Use
readBodyfor POST/PUT,getQueryfor GET params,getRouterParamfor path params - Return typed objects — Nitro infers the response type
Template: GET Route
// server/api/[resource]/index.get.ts
export default defineEventHandler(async (event) => {
const session = await requireUserSession(event)
const query = getQuery(event)
// Validate query params
const page = Number(query.page) || 1
const limit = Math.min(Number(query.limit) || 20, 100)
// Your logic here
const data = await db.select().from(myTable).limit(limit).offset((page - 1) * limit)
return {
data,
pagination: { page, limit },
}
})Template: POST Route
// server/api/[resource]/index.post.ts
export default defineEventHandler(async (event) => {
const session = await requireUserSession(event)
const body = await readBody(event)
// Validate body
if (!body.name) {
throw createError({ statusCode: 400, statusMessage: 'name is required' })
}
const result = await db.insert(myTable).values({
...body,
userId: session.user.id,
}).returning()
return result[0]
})Template: Webhook (Public, no auth)
// server/api/webhooks/[provider].post.ts
export default defineEventHandler(async (event) => {
// Verify webhook signature
const signature = getHeader(event, 'x-signature')
if (!signature) throw createError({ statusCode: 401 })
// ... verify signature
const body = await readBody(event)
// process webhook
return { received: true }
})Template: File Upload
// server/api/upload.post.ts
export default defineEventHandler(async (event) => {
await requireUserSession(event)
const files = await readMultipartFormData(event)
if (!files?.length) throw createError({ statusCode: 400, statusMessage: 'No files' })
// Process files
// ...
return { url: '...' }
})Steps
- Ask: what HTTP method, what path, what does it do?
- Is it public or protected?
- Generate following the appropriate template
- If it handles file uploads, ask about storage strategy
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

