agentleFS
violacaseviolacase/Nuxt4-test/.claude/skills/new-server-route/SKILL.md

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.

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
  1. Very specific:

    Place in server/api/ (accessible at /api/[name]) or server/routes/ (accessible at /[name])

    line 10
  2. Very specific:

    Always validate input with explicit checks — no raw body without validation

    line 11
  3. Very specific:

    Always protect with requireUserSession(event) unless explicitly public

    line 12
  4. Very specific:

    Use readBody for POST/PUT, getQuery for GET params, getRouterParam for path params

    line 13
  5. Distinctive:

    Ask: what HTTP method, what path, what does it do?

    line 94
  6. Distinctive:

    If it handles file uploads, ask about storage strategy

    line 97

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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]) or server/routes/ (accessible at /[name])
  • Always validate input with explicit checks — no raw body without validation
  • Always protect with requireUserSession(event) unless explicitly public
  • Use readBody for POST/PUT, getQuery for GET params, getRouterParam for 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

  1. Ask: what HTTP method, what path, what does it do?
  2. Is it public or protected?
  3. Generate following the appropriate template
  4. If it handles file uploads, ask about storage strategy

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.