标头值:application/vnd.api+json
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28055526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Header value: application/vnd.api+json
提问by RockNinja
Can someone explain the differences between:
有人可以解释以下之间的区别吗:
application/vnd.api+json
and
和
application/json
采纳答案by Gordon McCreight
The media type application/vnd.api+jsonrefers to JSON API. You can read about it in great detail here.
媒体类型application/vnd.api+json是指 JSON API。您可以在此处详细了解它。
In short, JSON API is an opinionated and well reasoned:
简而言之,JSON API 是一个自以为是且有充分理由的:
…specification for how a client should request that resources be fetched or modified, and how a server should respond to those requests.
...客户端应如何请求获取或修改资源的规范,以及服务器应如何响应这些请求。
回答by rmhartog
The first is an API specific media type. The vendor prefix (vnd.) indicates that it is custom for this vendor. The +jsonindicates that it can be parsed as JSON, but the media type shoulddefine further semantics on top of JSON.
第一个是 API 特定的媒体类型。供应商前缀 ( vnd.) 表示它是为此供应商定制的。的+json指示,它可以被解析为JSON,但媒体类型应当限定于JSON的顶部进一步语义。
The second just means that the content is JSON. This is in general not very useful, though, because it does not define what the JSON values mean.
第二个只是意味着内容是 JSON。但是,这通常不是很有用,因为它没有定义 JSON 值的含义。
A good starting point to read about this would be on Wikipedia, but for more details you can always follow the links to the corresponding RFCs on that page.
阅读这方面的一个很好的起点是在Wikipedia 上,但有关更多详细信息,您始终可以访问该页面上相应 RFC 的链接。
回答by Nickolay
If you're not sure, use application/json-- it's the generic MIME type that only requires the data you return to be a well-formed JSON.
如果您不确定,请使用application/json-- 它是通用 MIME 类型,它只要求您返回的数据是格式良好的 JSON。
The application/vnd.api+jsonMIME type is reserved for communication using the (confusingly named) "JSON API"protocol.
的application/vnd.api+jsonMIME类型是使用(容易混淆的命名)保留用于通信“JSON API”协议。
"JSON API" in this context does notmean anyAPI based on HTTP and JSON. It's not a fully-specified API either - rather it's a frameworkfor building APIs that allow the client to fetch and modify interrelated entities. For example, a blog application could implement an API conforming to the "JSON API" specification, that allows fetching last 10 articles by a given author, with metadata and comments for each article, in a single HTTP request.
这里的“JSON API”并不意味着任何基于 HTTP 和 JSON 的 API。它也不是一个完全指定的 API——而是一个用于构建允许客户端获取和修改相关实体的 API的框架。例如,博客应用程序可以实现符合“JSON API”规范的 API,允许在单个 HTTP 请求中获取给定作者的最后 10 篇文章,以及每篇文章的元数据和评论。
The specification defines, in particular:
该规范特别定义了:
- the specific way a request should be formed (i.e. what URL parameters control sorting and pagination and the data included in the output);
- the specific structure of the JSON document in the response, for example:
A document MUST contain at least one of the following top-level members:
data: the document's “primary data”errors: an array of error objectsmeta: a meta object that contains non-standard meta-information.
The members
dataanderrorsMUST NOT coexist in the same document.
- 应该形成请求的具体方式(即哪些 URL 参数控制排序和分页以及输出中包含的数据);
- 响应中 JSON 文档的具体结构,例如:
文档必须至少包含以下顶级成员之一:
data:文档的“主要数据”errors: 错误对象数组meta:包含非标准元信息的元对象。
成员
data和errors不得共存于同一个文档中。
回答by Tom Taylor
The Multipurpose Internet Mail Extensions (MIME) type(or) media type is a standardized way to indicate the nature and format of a document transferred over the internet. It is standardized in IETF RFC 6838. The Internet Assigned Numbers Authority (IANA)is the official body responsible for keeping track of all official MIME types.
该多用途Internet邮件扩展(MIME)类型(或)媒体类型是一种标准化的方式来表示通过Internet传输文件的性质和格式。它在IETF RFC 6838 中标准化。在互联网编号分配机构(IANA)负责保持所有正式的MIME类型的赛道的官方机构。
The media type used by JSON APIis application/vnd.api+jsonand it has been properly registered with IANA.
JSON API使用的媒体类型是application/vnd.api+json并且它已正确注册到 IANA。
The API+JSON media type is for interoperability between different API's that serve JSON.
API+JSON 媒体类型用于提供 JSON 的不同 API 之间的互操作性。
It was created with consideration from "thick JavaScript" clients and their needs, but is not specific to them. So, prefixed with vnd(vendor).
它的创建考虑了“厚 JavaScript”客户及其需求,但并非特定于他们。因此,前缀为vnd(供应商)。
Adding few more points on JSON API :
在 JSON API 上添加更多点:
- JSON API is a specification which defines an api specification on how a request and response and should be.
- Allows us to create have a well defined structure (like resource - relationships and it's links etc..)
- Specifies how the REST APIs should react for CRUDoperations.
- Allows client to cache the responses.
- JSON API 是一个规范,它定义了关于请求和响应如何以及应该如何的 API 规范。
- 允许我们创建具有明确定义的结构(如资源 - 关系及其链接等。)
- 指定 REST API 应如何对CRUD操作做出反应。
- 允许客户端缓存响应。
回答by Mahesh Yadav
If you need to setup the below header application/vnd.hmrc.1.0+json
如果你需要设置下面的头文件 application/vnd.hmrc.1.0+json
Then you should go with
那你应该去
Accept: application/vnd.hmrc.1.0+json
Using the CUrl you can run the script as
使用 CUrl,您可以将脚本运行为
$url="https://test-api.service.hmrc.gov.uk/hello/world";
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => array('Accept: application/vnd.hmrc.1.0+json')
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
Hope It helps!!
希望能帮助到你!!

