← スキル一覧に戻る
1. Route (
2. Controller (
3. Register (

api-endpoint
by Holo00
⭐ 0🍴 0📅 2025年11月28日
SKILL.md
name: api-endpoint description: Create or modify API endpoints in IdeaForge backend. Triggers: new route, controller, service, repository, CRUD operation, Zod validation, API debugging. Pattern: Routes → Controller → Service → Repository.
API Endpoints
Architecture
Route (backend/src/api/routes/) → DI setup + routing
Controller (backend/src/api/controllers/) → Zod validation + ApiResponse
Service (backend/src/services/) → Business logic
Repository (backend/src/repositories/) → Database queries
Quick Start
1. Route (routes/{resource}.ts)
import { Router } from 'express';
const router = Router();
// Manual DI
const repo = new MyRepository();
const service = new MyService(repo);
const controller = new MyController(service);
router.get('/', (req, res, next) => controller.getAll(req, res, next));
router.post('/', (req, res, next) => controller.create(req, res, next));
export default router;
2. Controller (controllers/{resource}Controller.ts)
const CreateSchema = z.object({
name: z.string().min(1).max(255),
});
export class MyController {
constructor(private service: MyService) {}
async create(req: Request, res: Response, next: NextFunction) {
try {
const data = CreateSchema.parse(req.body);
const result = await this.service.create(data);
res.json({ success: true, data: result } as ApiResponse<typeof result>);
} catch (error) {
next(error);
}
}
}
3. Register (index.ts)
import myRouter from './api/routes/my';
app.use('/api/my-resource', myRouter);
Response Format
// Success
{ success: true, data: { ... } }
// Error (via errorHandler middleware)
{ success: false, error: { message: "...", code: "ERROR_CODE" } }
Rules
- Controllers: validation + response only
- Services: all business logic
- Always use
ApiResponse<T>wrapper - Always
next(error)- never catch and format - Zod for all input validation
- Manual DI in route files
スコア
総合スコア
50/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です