Skip to content
MundoProgra JSON:API
Menu

Reference

Naming style

A multi-word name, such as the creation date, can be written three ways in the document. The package converts for you; in your code you always write snake_case.

The three styles

The member_case option (variable JSON_API_MEMBER_CASE, default camel) decides how multi-word names are written in the document:

ValueHow created_at is writtenSort example
camelcreatedAtsort=-createdAt
kebabcreated-atsort=-created-at
snakecreated_atsort=-created_at

The JSON:API 1.1 specification recommends camelCase for member names, which is why it is the default. kebab and snake are your choice, and the package supports them just the same.

What changes and what does not

The style applies, on input and output, to:

  • attributes and relationships;
  • the sort and fields parameters;
  • the pagination meta (for example current-page with kebab).

Types, ids, links and error pointers do not change with the style.

In your code

You always write snake_case, as in Eloquent: 'created_at' => $this->created_at in the resource, jsonApiSort(['created_at']) in the controller. The package converts the name to the configured style when it responds, and the one that comes from the client to snake_case when it reads it. If you change the style, your code does not change.

JSON_API_MEMBER_CASE=kebab