HTTP Methods (5)

HTTP Headers (1)

Miscellaneous (3)

Resources (4)

Basics (5)

Mediatypes (1)

我该如何创建属于自己的代表 users、categories、articles 的自定义 content-types?

不要使用标准的 text/xml content-type。一个客户端并没有能力处理这类信息,反而,使用如下自定义格式:

Content-type: application/vnd+company.category+xml
Content-type: application/vnd+company.category+html
Content-type: application/vnd+company.category+json

这允许你的客户端处理指定 content-type 的信息(在这个例子中是:categories)。 所有这三种 content-type 都是 categories,但由不同的格式(xml、html 和 json)表示。尽管这仍需要客户端 进一步理解这些信息,但它知道有那此预期,因为他们可能要求指定的信息(categories,在这个例子中),而不需要额外的 信息,如 URL 等。

所有 application/vnd 都是提供商自定的 content-type 而不是标准。仅应用于非标准 content-type。

Copyright 2012 Joshua Thijssen and others. Like to contribute? Add your recipe to our github repository.
Looking for Puppet recipies? Try the Puppet CookBook.
Fork me on GitHub