gpt4 book ai didi

http - RESTfully 请求表示的子部分具有特定的内容类型

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:11:17 24 4
gpt4 key购买 nike

我请求(通过 Accept: application/json)我正在设计的 API 响应为 JSON。但是,我希望根据客户端的功能指定该 JSON 中的值符合 text/plaintext/html

“子类型”的 RESTful 最佳实践是什么?如果我正式切换到 HAL 作为顶级容器,这将如何工作?

接受:application/json+text/plain

{
"value": "Hello World"
}

接受:application/json+text/html

{
"value": "<h2>Hello World</h2>"
}

最佳答案

您是否考虑过在 Accept: header 中使用参数?例如,请参阅如何为 JSON-LD http://json-ld.org/spec/latest/json-ld-syntax/#application-ld-json 定义配置文件参数.因此,例如您的接受 header 将是应用程序/json; profile="http://mysite.org/json-type/html"

另请记住,RFC 1341 中定义的 X- 字段已弃用:https://www.rfc-editor.org/rfc/rfc6648

关于http - RESTfully 请求表示的子部分具有特定的内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13059112/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com