如何在 JSON:API 中写入两个字的类型?

How do I write a two-word type in JSON:API?

我想 post 一个外星神器到我的服务器。

我写type="alienArtifact"

或输入="alien-artifact"

还是完全不同的东西?

我看了这里 https://jsonapi.org/format/ 但只处理简单类型,"objects"。

如果您使用 kebab-casesnake_casecamelCase 作为字段名称,则

JSON:API 规范是不可知的,但它带有 recommendation:

Member names SHOULD be camel-cased (i.e., wordWordWord)

此建议于 2018 年 10 月更改。之前是 kebab-case。因此,许多关于 JSON:API 库规范和文档的文章仍在使用 kebab-case。这些论点被认为是这一变化的主要原因:

  • camelCased names can be used directly as identifiers in almost all programming languages, making json:api easier to get started with and to work with over time. Dasherized names are usable as identifiers pretty much only in Lisps.

  • camelCased names are the most common convention in the JS community, and JS is the biggest user of JSON:API

  • camelCased names are slightly shorter than dasherized (or snake-case) names, which could help with url character limits in the case of complex filters or other types of complex queries (e.g., some GraphQL like “deep querying” feature) that we might serialize into urls in the future.

您可以在 appropriate pull request 中找到有关此更改的更多详细信息。