Skip to main content

Appendix B. Using Problem Details with Other Formats (在其他格式中使用问题详情)

在某些情况下,将问题详情嵌入除此处描述的格式之外的格式中可能是有利的。例如,使用 HTML [W3C.REC-html5-20141028] 的 API 可能也希望使用 HTML 来表达其问题详情。

问题详情可以通过以下方式嵌入到其他格式中:将现有序列化(JSON 或 XML)之一封装到该格式中,或者将问题详情的模型(如第 3 节中指定的)转换为该格式的约定。

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

<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] 的映射。

本规范不对将问题详情嵌入其他格式做出具体建议;嵌入它们的适当方式既取决于所使用的格式,也取决于该格式的应用。

致谢 (Acknowledgements)

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

作者地址 (Authors' Addresses)

Mark Nottingham
Akamai

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

Erik Wilde

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