npx agentspec-cli install c809ab21-6994-4df6-a70e-2e14584de9b4 --framework ClaudeCode→ .claude/skills/API Route Conventions/SKILL.md
# API Route Conventions
## Imports
Always use `NextRequest` and `NextResponse`:
```typescript
import { NextRequest, NextResponse } from "next/server";
```
## Input Validation
Validate all query parameters before using them:
```typescript
const code = searchParams.get("code");
if (!code || code.trim() === "") {
return NextResponse.json({ error: "O campo 'code' é obrigatório." }, { status: 400 });
}
```
## Token Handling
Read `BRAPI_TOKEN` from `process.env` — never hardcode or pass to the client:
```typescript
const token = process.env.BRAPI_TOKEN;
if (!token) {
return NextResponse.json({ error: "Token da API não configurado." }, { status: 500 });
}
```
## Brapi Fetch Pattern
- Normalize tickers to uppercase before calling Brapi
- Use `next: { revalidate: 60 }` to cache responses for 60 seconds
- Mirror Brapi's HTTP status code back to the client
```typescript
const ticker = code.trim().toUpperCase();
const url = `https://brapi.dev/api/quote/${encodeURIComponent(ticker)}?token=${token}`;
const res = await fetch(url, { next: { revalidate: 60 } });
const data: BrapiResponse = await res.json();
return NextResponse.json(data, { status: res.status });
```
## Error Response Shape
Always return `{ error: string }` for error responses so the client can read `data.error`.
Built on the Agent Skills standard
next-best-practices
Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling
by AgentHub Crawler
React Typescript Nextjs Nodejs Cursorrules Prompt Rules
Cursor IDE rules and conventions for AI-assisted development.
by AgentHub Crawler
Next.js Best Practices
Cursor IDE rules and conventions for AI-assisted development.
by AgentHub Crawler
TypeScript Patterns
Sign in to leave a comment.
// Prefer explicit interfaces over type inference interface ApiParameter { in: 'path' | 'query' | 'header' | 'body'; // Use discriminated unions for type safety | { type: 'path'; name: string; value: string }
by AgentHub Crawler