Problem/Motivation
A json or hal+json request leads to 'deep' nested data structures.
$ curl --user admin:admin --header 'Accept: application/json' --header 'Accept-Language: nl' --header 'Content-Language: nl' --request GET http://drupal.d8/node/1 | json_pp
{
...
"changed" : [
{
"value" : "1411395751"
}
],
...
"title" : [
{
"value" : "Importunus Letalis Ludus Luptatum Ut"
}
],
...
Why not remove the list-ness for single value items into key-value pairs? Or at least remove the array-ness
{
...
"changed" : "1411395751"
...
"title" : "Importunus Letalis Ludus Luptatum Ut"
...
Why not allow to configure what to output for compound fields like body, field_image like: summary, format, value, alt, title, width, height?
Why not add the image uri for image_fields?
This boils down to field formatters combined with #2339795: Add "REST modes", just like we have "view modes" and "form modes" AND depth argument to reduce # of requests
Proposed resolution
tbd
Remaining tasks
User interface changes
API changes
Comments
Comment #1
briward commentedI would agree that it's important to not expose system-information within an API. However, while this is waiting to be decided you could always create a data transformer within a custom RestResource class to handle this.
Comment #2
dawehnerWell you know its tricky, given that all those things could be multivalues as well. Making it clear that all fields are actually list of data is not the worst idea IMHO
Comment #3
wim leersWhat #2 says. There's sadly no way around it. We should provide basic JS libraries that makes it simpler to deal with this though.
Comment #4
dawehnerIf you really worry about you can still provide some custom code to just return exactly what you want, but in order to provide any kind of generic interaction with Drupal, the current behaviour is needed.
Comment #5
clemens.tolboomThanks for closure: as read in #2339795: Add "REST modes", just like we have "view modes" and "form modes" AND depth argument to reduce # of requests we built a data sync tools which has some value. Headless developers should write transformers to/from Drupal json to make this easier like I did in trying to cope with hal vs json through test project https://github.com/clemens-tolboom/drupal-8-rest-angularjs