跳到主要内容

Appendix B. 在其他格式中使用问题详情

在某些情况下, 将问题详情 (problem details) 嵌入到本文所述格式以外的其他格式中可能是有利的. 例如, 使用 HTML [W3C.REC-html5-20141028] 的 API 可能也希望使用 HTML 来表达其问题详情.

问题详情可以通过两种方式嵌入到其他格式中: 将现有序列化形式之一 (JSON 或 XML) 封装到该格式中, 或者将问题详情模型 (如 Section 3 所规定) 转换为该格式的约定.

例如, 在 HTML 中, 可以通过在 script 标签中封装 JSON 来嵌入一个问题:

<script type="application/problem+json">
{
"type": "https://example.com/probs/out-of-credit",
"title": "You do not have enough credit.",
"detail": "Your current balance is 30, but that costs 50.",
"instance": "/account/12345/msgs/abc",
"balance": 30,
"accounts": ["/account/12345",
"/account/67890"]
}
</script>

或者设计一种到 RDFa [W3C.REC-rdfa-core-20130822] 的映射.

本规范不对如何在其他格式中嵌入问题详情提出具体建议. 适当的嵌入方式同时取决于所使用的格式以及该格式的应用方式.

致谢

作者感谢 Jan Algermissen, Subbu Allamaraju, Mike Amundsen, Roy Fielding, Eran Hammer, Sam Johnston, Mike McCall, Julian Reschke, 和 James Snell 对本规范的审阅.

作者地址

Mark Nottingham
Akamai

Email: [email protected]
URI: https://www.mnot.net/

Erik Wilde

Email: [email protected]
URI: http://dret.net/netdret/