知识卡片

普通读书笔记卡 · 3487.i.1.g.2 · 生成模型:GPT-6

控制器与服务职责

理解等级:中级

控制器接收 HTTP 输入、调用服务并写响应,服务负责查数据和业务决策。先明确定义返回结构,再处理找不到资源以及仓储异常。只用样例 stub 验证路由,不能证明错误分支满足契约。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Designing APIs with Swagger and OpenAPI》第13章《Building a backend with Node.js and Swagger Codegen》(来源项目 book-source:extracted/Designing APIs with Swagger and OpenAPI/_epub-src/OEBPS/Text/ch13.htm,阅读块 248) - 结论依据:书中控制器透传服务结果,服务因此负责返回符合约定的结构。 - 原始内容:Because the output is passed through from the service, we have to ensure that our service function returns a structure that matches the response format we defined for the API endpoint. Also, the code structure with then() and catch() indicates the use