使用 jsonapi 的配置问题
我打算使用json:api这个规范的,根据其文档:
Client Responsibilities
Clients MUST send all JSON:API data in request documents with the header Content-Type: application/vnd.api+json without any media type parameters.Clients that include the JSON:API media type in their Accept header MUST specify the media type there at least once without any media type parameters.
Clients MUST ignore any parameters for the application/vnd.api+json media type received in the Content-Type header of response documents.
Server Responsibilities
Servers MUST send all JSON:API data in response documents with the header Content-Type: application/vnd.api+json without any media type parameters.Servers MUST respond with a 415 Unsupported Media Type status code if a request specifies the header Content-Type: application/vnd.api+json with any media type parameters.
Servers MUST respond with a 406 Not Acceptable status code if a request’s Accept header contains the JSON:API media type and all instances of that media type are modified with media type parameters.
也就是说Content-Type和Accept必须为application/vnd.api+json,那么是否就是说这里的配置API_STANDARDS_TREE应该为vnd,而API_SUBTYPE呢?这个怎么配置?是否在这里配置了之后我后端的header就可以为application/vnd.api+json,而不需要再做其他配置了呢?我看了《RESTful Web APIs》一书,醍醐灌顶,只是目前空有理论,也许还要跳一些坑才能认清这方面理论与实践的差异。
关于 LearnKu
这个头还涉及切换版本,就按 dingo 的来呗,
@liyu001989 那就是说不用json:api? 我就是没弄明白如果用json:api应该怎么配置
json api 包括的东西这么多,就因为一个 header 稍微不一样就不用了?
想用就可以用啊,重要的不是响应的数据结构吗,https://github.com/liyu001989/dingo-serial... 中间件设置 json_api,就可以用了。
@liyu001989 不好意思,可能我没有表达清楚。并不是我不想用
json:api。看了《RESTful Web APIs》一书,我很喜欢这个开放性的规范,毕竟这属于书上说的四个标准之一,而且是比较好的标准。只是在dingo这里,我不知道怎么才能将Accept配置成application/vnd.api+json,json:api的API版本号好像不放在媒体类型里。我做了如下配置:严格模式,必须带上
Accept,但是此时Accept必须为application/vnd.api.v1+json,里边要带上v1这个版本号。即便不设置严格模式,访问非默认的v2,Accept也必须为application/vnd.api.v2+json你的意思就是 必须完全按照 json:api 来,accept 必须是 application/vnd.api+json。
那么想办法就别让 dingo 解析这个头,不然可能就报错了。要么就别用 dingo 了,你需要的只是 fractal 而已。