Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position on sparse fieldsets #159

Open
cmars opened this issue Feb 3, 2022 · 2 comments
Open

Position on sparse fieldsets #159

cmars opened this issue Feb 3, 2022 · 2 comments

Comments

@cmars
Copy link
Contributor

cmars commented Feb 3, 2022

It may be necessary / useful for a client to request only a subset of attributes on a resource, especially when paging through a high volume of them.

JSON API provides for this with sparse fieldsets.

We need to document our position on these. My thinking is currently:

  • Drop the square-bracket notation for reasons already stated in the docs: they're ugly (forces "percent" URL encoding, hard to read and write) and unnecessary (we don't allow compound documents, so there's no need to differentiate type)
  • If fields is not defined as a parameter, resource does not support sparse fieldsets and returns everything.
  • If fields is defined as a parameter:
    • It must be style: form, explode: false. This defines a comma-separated []string like ?fields=a,b,c.
    • No fields parameter present in the request means I'm not filtering fields, so "give me everything"
    • ?fields= means "I don't want any fields at all" (empty or omitted attributes)
@cmars
Copy link
Contributor Author

cmars commented Feb 3, 2022

What about sparse fields in nested attributes?

We might use a dot notation for this. Given a resource like:

data: {
  id: some-id,
  type: some-type,
  attributes: {
    package: {
      name: "lodash",
      version: "1.0.3",
      dependencies: [{
        name: "nodash",
        version: "2.0.1",
      }, {
        name: "slodash",
        version: "4.2.7",
      }],
    }}}

?fields=package yields the full nested contents of the package property.
?fields=package.name yields only the name property in in the package property object.
?fields=package.name,package.dependencies..name yields only:

  • The name in each package object.
  • The name in each dependencies array's item, in each package object.
    Like this:
data: {
  id: some-id,
  type: some-type,
  attributes: {
    package: {
      name: "lodash",
      dependencies: [{
        name: "nodash",
      }, {
        name: "slodash",
      }],
    }}}

This resembles JSON Path, without the leading $.. Which gives me some pause for concern, as I'm not sure we want to invite a full JSON Path implementation here, or even advertise it as such.

@cmars
Copy link
Contributor Author

cmars commented Jun 9, 2022

I think instead of fields, attributes might be a better name for this. This is going to be a reserved query parameter name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant