YAML 媒体类型?
通过 HTTP 发送使用 YAML 构建的数据时最合适的媒体类型(正式的 MIME 类型)是什么?为什么?
示例:
> GET /example.yaml
< Content-Type: ????
<
< --- # Favorite movies
< - Casablanca
< - North by Northwest
< - Notorious
可能的选项:
- text/x-yaml
- text/yaml
- text/yml
- application/x-yaml
- application/x-yml
- application/yaml
- application/yml
What is the most appropriate media type (formally MIME type) to use when sending data structured with YAML over HTTP and why?
There is no registered application type or text type that I can see.
Example:
> GET /example.yaml
< Content-Type: ????
<
< --- # Favorite movies
< - Casablanca
< - North by Northwest
< - Notorious
Possible options:
- text/x-yaml
- text/yaml
- text/yml
- application/x-yaml
- application/x-yml
- application/yaml
- application/yml
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
Ruby on Rails 使用
application/x-yaml
以及text/yaml
的替代方案 (来源)。我认为这只是一个惯例问题,据我所知,没有任何技术原因。
Ruby on Rails uses
application/x-yaml
with an alternative oftext/yaml
(source).I think it's just a matter of convention, there is no technical why, as far as I can tell.
尽管另一个答案已被接受,但请参阅此 建议的媒体类型 剑桥大学信息服务部的 Ben Harris 在 2015 年 7 月代表 YAML 团队提议媒体类型:
IANA 邮件列表上的 YAML 注册线程用于审查媒体类型, (建议)已弃用的别名:
仍然建议/待定(该线程不指示建议的状态),因此这个答案并不比其他答案更明确:-)
Although another answer was accepted, please refer to this Proposed media type registration for YAML thread on the IANA mailing list for reviewing Media Type in which Ben Harris, University of Cambridge Information Services, proposed in July 2015 on behalf of the YAML team the media type:
with (suggested) deprecated aliases:
That is still proposed/pending (the thread does not indicate status of the proposal) so this answer is no more definitive than the others :-)
我会说
text/x-yaml
:text
overapplication
因为它是人类可读的x-yaml
超过yaml
因为它尚未被接受到 mime 类型的注册列表中。编辑:来自 RFC 3023(XML 媒体类型):
有趣...不太清楚这意味着什么,但值得深思。
I'd say
text/x-yaml
:text
overapplication
because it's a human-readablex-yaml
overyaml
because it hasn't been accepted into the registered list of mime types.Edit: from RFC 3023 (XML Media Types):
Interesting... Not exactly sure what it means, but food for thought.
在 Chrome 上,
application/yaml
将下载,而text/yaml
将显示。On Chrome
application/yaml
will download, whiletext/yaml
will display.IETF 正在努力注册
application/yaml
媒体类型和+yaml
结构化语法后缀。目前,我们尚未注册
text/yaml
。 https://github.com /ietf-wg-httpapi/mediatypes/blob/main/draft-ietf-httpapi-yaml-mediatypes.md欢迎参与讨论。
The IETF is working to register the
application/yaml
media type and the+yaml
structured syntax suffix.Currently, we are not registering
text/yaml
. https://github.com/ietf-wg-httpapi/mediatypes/blob/main/draft-ietf-httpapi-yaml-mediatypes.mdFeel free to participate in the discussion.
不鼓励使用“x-”媒体类型,请参阅 RFC 4288,第 3.4 节。 正确的做法是使用个人树、供应商树,或者实际尝试正确的媒体类型注册。
"x-" media types are discouraged, see RFC 4288, Section 3.4. The right thing to do is to use the personal tree, the vendor tree, or to actually attempt a proper media type registration.
我不确定是否将此作为答案发布或作为对另一个答案的评论。 (作为单独的答案发布,因为它相当长。)
然而,我也想知道同样的事情,于是我搜索了 IANA 列表。
目前 (2023-05-13) 有草稿条目 用于在 IANA 列表中注册 YAML。 在 mime-type 下注册它:
但是,它还没有被添加,我不知道剩下的过程会持续多久。
06 草案 IANA 声明:
其中:
需要审核
,意思是:文件尚未经过 IANA 审核。
[ review-state ]更新 (2023-06-06)
草案 07 审核状态更改为:
其中 < code>IANA OK - 需要采取行动,意思是:
文档需要 IANA 采取行动,IANA 注意事项部分正确指示了行动的详细信息。
以及正在进行中
表示:IANA 当前正在处理此文档的操作
,专家审核正常
表示:所有专家审核均已完成,没有任何阻塞问题
。更新 (2024-01-30)
目前处于草案版本 10,进展速度没有我预期的那么快,祈祷 2024 年注册。
更新 (2024-03-19)< /em>
正如其他人提到的:
草案现已转移到官方 RFC。
请参阅https://datatracker.ietf.org/doc/rfc9512/
I'm unsure whether to post this as an answer or as a comment to another answer. (Posting as separate answer as it's rather long.)
However, I was wondering the same thing and I searched the IANA listing.
There's currently (2023-05-13) a draft entry for registering YAML in the IANA listing. Registering it under the mime-type:
However, it's not been added yet and I do not know how long the rest of the process is going to last.
Draft 06 IANA state:
Where:
Review Needed
, means:Document has not yet been reviewed by IANA.
[ review-state ]Update (2023-06-06)
Draft 07 Review State changed to:
Where
IANA OK - Actions Needed
, means:Document requires IANA actions, and the IANA Considerations section indicates the details of the actions correctly.
and,In Progress
means:IANA is currently processing the actions for this document
and,Expert Reviews OK
means:All expert reviews have been completed with no blocking issues
.Update (2024-01-30)
Currently in draft version 10, not moving as fast as I had expected, fingers crossed for a registration in 2024.
Update (2024-03-19)
As mentioned by others:
Draft has now moved to official RFC.
See https://datatracker.ietf.org/doc/rfc9512/
我在与 TOML 文件格式的 MIME 类型相关的类似非常有趣的对话之后读到了这篇文章。
application/*
与text/*
来自 RFC (https://tools.ietf.org/html/rfc2046#section-3)
来自评论 https://github.com/toml-lang/toml/问题/465#issuecomment-306231107
我们可以对 YAML 格式说同样的话,所以我个人更喜欢
application/*
。application/*
的另一个论点是YAML
是JSON
的超集,并且使用 MIME 类型application/json
对于JSON
。application/yaml
与application/x-yaml
除非 MIME 类型已正式注册(假设任何人都计划这样做),否则应使用 application/x-* 。
由于 YAML(以及 TOML)未正式注册,因此最好使用
x-
前缀,因此我们得到application/x-yaml
作为结果。有趣的事实:TOML 官方文档建议使用
application/toml
,即使它还不是官方的。 但并非所有人都认为这是一个正确的决定。Postman 使用
application/x-yaml
这是使用此类 MIME 类型的另一个原因:)
I read this after similar really interesting conversation related to about MIME type for TOML file format.
application/*
vstext/*
From RFC (https://tools.ietf.org/html/rfc2046#section-3)
From comment https://github.com/toml-lang/toml/issues/465#issuecomment-306231107
We can say the same about YAML format so personally I would prefer
application/*
.Another argument for
application/*
is thatYAML
is a superset ofJSON
and MIME typeapplication/json
is used forJSON
.application/yaml
vsapplication/x-yaml
Unless the MIME type has officially been registered (assuming that anyone even plans to do that), application/x-* should be used.
Since YAML (as well as TOML) is not registred officially it's better to use
x-
prefix so we haveapplication/x-yaml
as a result.Interesting fact: TOML official docs suggest using
application/toml
even if it's not official yet. But not everyone thinks that this is a right decision.Postman uses
application/x-yaml
Just another reason to use such MIME type :)
来自 https://httptoolkit.com/blog/yaml-media-type-rfc/
From https://httptoolkit.com/blog/yaml-media-type-rfc/
现在我们有 RFC 9512:
Now we have RFC 9512:
根据 MIME 类型列表,它是
text/yaml
,即使它不在官方 IANA MIME 列表中As per MIME Types list it's
text/yaml
, even though it's not in official IANA MIME list