Skip to content

Transformation

Max edited this page Oct 21, 2018 · 5 revisions

This boilerplate contains a very rich transformation layer, containing a lot of useful functionality.

Relations Transformation

All relations which have been loaded in the model(s) which are being transformed for response, themselves will get transformed using their own transformers. This works recursively. All related models will appear as nested objects in the response.

Case Type

One of the features of this boilerplate is to allow for configuring which case type you would like in your responses. Currently the options "camel-case" and "snake-case" are supported.

Change through config

You can change this setting in your config/api.php file, the setting is under the name "formatsOptions.caseType".

Change through request headers

This boilerplate also accepts a special header named "X-Accept-Case-Type", which will override any configuration (as specified above) and allow the request caller to specify the case type they would prefer.

This is especially useful if you have multiple API consumers, and they have different preferences for case type.

PHP Guzzle Example:

$api->get('http://your-api.com/resource', [
    'headers'         => ['X-Accept-Case-Type' => 'snake-case'],
]);