원클릭으로
api-endpoint-creation
Guide for creating RESTful API endpoints with validation and error handling. Use when implementing backend API routes.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Guide for creating RESTful API endpoints with validation and error handling. Use when implementing backend API routes.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
| name | api-endpoint-creation |
| description | Guide for creating RESTful API endpoints with validation and error handling. Use when implementing backend API routes. |
Follow this process to create robust API endpoints:
// Example: Express.js endpoint
import { Router } from 'express';
import { z } from 'zod';
const router = Router();
router.post('/api/users', async (req, res) => {
try {
// 1. Validate input
// 2. Business logic
// 3. Database operation
// 4. Return response
} catch (error) {
// 5. Error handling
}
});
Use Zod for schema validation:
const createUserSchema = z.object({
email: z.string().email(),
name: z.string().min(2).max(100),
age: z.number().int().positive().optional(),
});
// In route handler
const validatedData = createUserSchema.parse(req.body);
Use appropriate status codes:
200 OK - Successful GET, PUT, PATCH201 Created - Successful POST204 No Content - Successful DELETE400 Bad Request - Validation error401 Unauthorized - Authentication required403 Forbidden - No permission404 Not Found - Resource not found409 Conflict - Resource conflict500 Internal Server Error - Server errorConsistent JSON response structure:
// Success
res.status(201).json({
data: user,
message: 'User created successfully',
});
// Error
res.status(400).json({
error: 'Validation failed',
details: validationErrors,
});
Centralized error handler:
class ApiError extends Error {
constructor(public statusCode: number, message: string) {
super(message);
}
}
// In route
if (!user) {
throw new ApiError(404, 'User not found');
}
// Error middleware
app.use((err, req, res, next) => {
if (err instanceof ApiError) {
return res.status(err.statusCode).json({ error: err.message });
}
res.status(500).json({ error: 'Internal server error' });
});
GET /api/users - List all users
POST /api/users - Create new user
GET /api/users/:id - Get single user
PUT /api/users/:id - Update user (full)
PATCH /api/users/:id - Update user (partial)
DELETE /api/users/:id - Delete user
For list endpoints:
router.get('/api/users', async (req, res) => {
const page = parseInt(req.query.page as string) || 1;
const limit = parseInt(req.query.limit as string) || 10;
const offset = (page - 1) * limit;
const [users, total] = await Promise.all([
db.user.findMany({ skip: offset, take: limit }),
db.user.count(),
]);
res.json({
data: users,
pagination: {
page,
limit,
total,
totalPages: Math.ceil(total / limit),
},
});
});
Checklist for auditing and fixing accessibility issues (WCAG 2.1 AA compliance). Use when reviewing components or pages for accessibility.
Guide for implementing secure authentication with JWT and session management. Use when adding authentication to an application.
Guide for creating responsive layouts with CSS. Use when implementing responsive design or fixing layout issues.
Guide for designing database schemas with Prisma ORM. Use when creating or modifying database models.
Guide for consistent error handling across frontend and backend. Use when implementing error handling logic.
Guide for implementing form handling with React Hook Form and Zod validation. Use when creating forms with validation.