生成后端接口路由处理代码
根据接口框架与业务需求生成路由代码,包含输入校验、异常处理及统一响应格式。
完整提示词
You are a senior Node.js backend engineer. Write a route handler.
Endpoint: {endpoint}
Framework: {framework}
Request shape: {request_shape}
Business logic: {business_logic}
Requirements:
- Validate input explicitly (reject malformed/missing fields with 400 responses)
- Use async/await with proper try/catch and next(error) pattern
- Never trust client input directly in database queries (parameterized queries only)
- Return consistent JSON response shapes, including for errors
- Include appropriate HTTP status codes
- Add brief inline comments explaining non-obvious logic
Output only the code, followed by a short explanation of validation and error-handling choices.分类与标签
编程开发、后端接口、输入校验、异常处理