使用 Kiro 入门 Spec 驱动开发

发布: (2025年12月14日 GMT+8 02:33)
3 min read
原文: Dev.to

Source: Dev.to

创建一个简易投票 API

你将构建的内容

一个简单的 REST API,用户可以:

  • 创建带选项的投票
  • 为投票投票
  • 查看投票结果

前置条件

下载并安装适用于你操作系统的 Kiro IDE

创建项目文件夹并开始开发!

  1. 创建项目文件夹
    在本地文件系统中创建一个名为 Kiro_Voting_API 的文件夹。

  2. 在 Kiro 中打开文件夹
    启动 Kiro,选择 File → Open Folder,打开刚才创建的文件夹。

    Launch Kiro, select File and open the folder

  3. 启动规范驱动会话
    从选项中选择 Spec

    Select Spec from the options

  4. 输入自然语言提示

    Build a simple poll and voting REST API using Python and FastAPI
    
    Requirements:
    - A poll has: id, question, options, votes
    - Options are strings
    - Votes are counted per option
    - Endpoints:
      - POST /polls to create a poll
      - GET /polls/{id} to retrieve a poll and its results
      - POST /polls/{id}/vote to vote for an option
    - Store all data in memory
    - Return JSON responses
  5. 生成需求文档
    Kiro 会创建包含需求、用户故事和验收标准的文档。

    Kiro creates a requirements document

  6. 细化需求(可选)

    Add support for displaying poll results as a percentage
    Poll results must be calculated as a percentage as well as displaying the raw numbers of votes
  7. 进入设计阶段
    当需求满意后,点击 Move to design phase

    If the requirements look good move to design phase

  8. 审阅生成的设计
    打开生成的 design.md 文件。设计中包括错误处理和测试策略(如果你想更快地做原型,可以后期再删减这些内容)。

    View the design document

  9. 进入实现计划
    在完成所有设计细节后,点击 Move to implementation plan。Kiro 会生成实现计划并创建 tasks.md 文件。

    Implementation plan ready

  10. 打开任务列表
    打开 tasks.md(通过顶部的 Task list 或在文件夹视图中打开)。

    Open tasks.md to view the implementation plan

  11. 开始实现
    在第一个任务上点击 Start task。Kiro 将设置环境、安装依赖(在你审阅 requirements.txt 后),并开始测试。

    Kiro can help you implement the feature you just designed

    Kiro asks permission before installing dependencies

  12. 遵循实现计划
    继续完成剩余任务。Kiro 会在每个阶段请求运行测试的权限,以确保代码按预期工作。

    Running tests at each stage to ensure everything is working

  13. 可选 – 在初始实现时,你可以跳过添加大量错误处理或响应格式化等步骤,之后根据需要再补充。

Back to Blog

相关文章

阅读更多 »