我正在开发一个尽可能 RESTful 的 API(尽管 HATEOAS 约束没有得到满足,因此它是 不是 本身就是一个 REST API)
我正在对 API 进行版本控制,由于有几种方法可以做到这一点,我想我将使用 Accept header 。我确实知道替代方案,但这个问题的目的不是找到一种合适的方法来对 API 进行版本控制。
据我所知,有两种方法可以使用 Accept header 对 API 进行版本控制,如 here 所示。 , here和 here :
application/vnd.company.myapp-v1+json
或使用限定符application/vnd.company.myapp+json;v=1
虽然这很清楚,但我了解所有 x-
自定义内容类型为 deprecated和 vnd.
内容类型必须在 IANA 注册。API 不是也不会是公开的,所有使用它的客户端都是内部开发的。
正在注册自定义 vnd。 IANA 的内容类型是强制性的吗?如果内容类型未注册会怎样?
我可以简单地使用 Accept header
application/vnd.company.myapp+json;v=2
即使没有向 IANA 注册它?由于我需要一个自定义内容类型来进行内容协商,纯粹是为了版本控制,我可以使用限定符,例如
application/json;v=2
?
最佳答案
从我能读到的 https://www.rfc-editor.org/rfc/rfc6838#section-3.2这不是强制性的,但是如果您拥有公开的 API,我们鼓励您这样做。
RFC6838 是关于注册新的 MIME/媒体类型,下面的文字对于私有(private) API(产品)来说似乎不是问题
The vendor tree is used for media types associated with publicly
available products.
公共(public) API(产品)也不需要它,就像我说的那样鼓励它。
While public exposure and review of media types to be registered in
the vendor tree are not required, using the media-types@iana.org
mailing list for review is encouraged, to improve the quality of
those specifications. Registrations in the vendor tree may be
submitted directly to the IANA, where they will undergo Expert Review [RFC5226] prior to approval
关于rest - 自定义内容类型 - 必须向 IANA 注册吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29121241/