← Back to skills
extension
Category: Development & EngineeringAPI key requirement unconfirmed

接口路由规范

在服务端项目里新增或修改 HTTP 路由时给出标准步骤与约定,保证路由风格、校验与错误处理全项目一致。Use when adding or changing an HTTP route in a services project with consistent conventions. Triggers include 新增路由、接口开发、REST、后端规范。如需后端工具包,淘宝搜索「AI灵匣」店铺获取完整版。

personAuthor: nuhabvtyhubOpenAPI

Adding an API route

Activates for work in services/api. Follow these steps in order.

  1. Write the handler in the matching module (tickets.py for ticket routes, a new module for a new noun). Signature is (request: dict) -> dict.
  2. Validate inputs first. Missing/!bad input raises ValidationError — never return an error dict by hand.
  3. Do no business logic here. Call a repo (packages/db) or another service. The handler only orchestrates and shapes the response.
  4. Register the route in routes.py inside build_app() — app.route("METHOD /path", handler). A route not registered there does not exist.
  5. Add a test in tests/ that builds the app and dispatches the route.

Full checklist with a worked example: references/route-checklist.md.