跳到主要内容

Appendix C. 在其他格式中使用 Problem Details (Using Problem Details with Other Formats)

在某些情况下, 将 problem details 嵌入到本文所述格式之外的其他格式中可能是有利的. 例如, 使用 HTML [HTML5] 的 API 可能也希望使用 HTML 来表达其 problem details.

problem details 可以通过两种方式嵌入其他格式: 将现有 serialization 之一 (JSON 或 XML) 封装到该格式中, 或将 problem detail 的模型 (如 Section 3 中规定) 转换为该格式的约定.

例如, 在 HTML 中, 可以通过在 script tag 中封装 JSON 来嵌入 problem:

<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>

也可以通过定义到 Resource Description Framework in Attributes (RDFa) [RDFA] 的映射来嵌入.

本规范不对在其他格式中嵌入 problem details 提出具体建议; 合适的嵌入方式同时取决于所使用的格式以及该格式的应用方式.