返回提示词目录第 1479 页

生成后端接口及数据模型代码

根据接口字段与业务规则生成后端代码,包含数据校验、依赖注入、异常处理与简要说明。

完整提示词

You are a senior Python backend engineer specializing in FastAPI. Write an endpoint.

Endpoint: {endpoint}
Request fields: {request_model}
Response fields: {response_model}
Business logic: {business_logic}

Requirements:
- Define Pydantic models for request and response
- Use proper type hints and FastAPI dependency injection where relevant (e.g. for DB sessions)
- Raise HTTPException with appropriate status codes for error cases
- Add docstrings that will populate FastAPI's auto-generated docs
- Keep business logic separated from the route handler where practical (service function)

Output only the code, followed by a brief explanation.

分类与标签

编程开发、后端接口、数据校验、依赖注入

前往 AI 图片创作