loopback-component-jsonapi icon indicating copy to clipboard operation
loopback-component-jsonapi copied to clipboard

Sparse Fieldsets

Open digitalsadhu opened this issue 10 years ago • 0 comments

Spare fieldsets is where the data returned from the server can be slimmed down by fields

eg. given the following data fetched using GET /api/projects/1

{
  "data": {
    "type": "projects",
    "id": 1,
    "attributes": {
      "name": "A project",
      "reference": "My project ref",
      "location": "Oslo",
      "summary": "A big project",
      "companyFor": "my company"
    }
  }
}

spare fieldsets can be used to return only a subset of the fields. GET /api/projects/1?fields[projects]=name

{
  "data": {
    "type": "projects",
    "id": 1,
    "attributes": {
      "name": "A project"
    }
  }
}

See http://jsonapi.org/format/#fetching-sparse-fieldsets for details in the JSON API spec.

Loopback already provides this functionality in the form of filter fields. https://docs.strongloop.com/display/public/LB/Fields+filter

Example:

filter[fields][propertyName]=<true|false>&filter[fields][propertyName]=<true|false>...

There are quite substantial differences in what JSON API expects and what loopback provides. I think it should be possible for us to do some sort of mapping but perhaps some kind of spike into how it might work is necessary.

I consider this fairly low priority for now as we have bigger fish to fry.

digitalsadhu avatar Nov 24 '15 09:11 digitalsadhu