知识卡片
宽容读取需权衡拼写风险
宽容读取允许请求带有未声明字段,接口演进时可能更容易兼容旧客户端;代价是拼写错误也会被忽略。订单数量写成 quantit 后落回默认值 1 就是例子。是否宽容应按契约变动频率与静默误处理的后果取舍。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 6 章《Building REST APIs with Python》(源文件:_epub-src/OEBPS/Text/06.htm)
- 结论依据:原文说明宽容读取有助于频繁变化的接口不破坏集成,同时以数量字段拼错导致默认值覆盖意图说明风险。
- 原始内容:The tolerant reader pattern is useful when an API is not fully consolidated or is likely to change frequently and when we want to be able to make changes to it without breaking integrations with existing clients. However, in other cases, like we saw in chapter 2 (section 2.5), the tolerant reader pattern can introduce new bugs or lead to unexpected integration issues .