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

API: Fields parameter #5601

Closed
ErisDS opened this issue Jul 25, 2015 · 0 comments
Closed

API: Fields parameter #5601

ErisDS opened this issue Jul 25, 2015 · 0 comments
Labels
affects:api Affects the Ghost API
Milestone

Comments

@ErisDS
Copy link
Member

ErisDS commented Jul 25, 2015

As mentioned in #5463, we want to add a new fields top-level parameter to API browse requests.

The fields parameter allows a user to specify exactly which fields from a model should be returned, to limit the size of the response.

It can be implemented by using the 'columns' property of the bookshelf fetch method, which hooks into the 'column' method of knex.

Any specified fields should be validated to ensure that they are valid attributes of the requested model. Note that this should include the url attribute of posts even though it is calculated, and not include the password attribute of users, as that is protected.

The response should be the standard format, but with only the fields that were requested.

Support for relations, where they exist (e.g. tags for posts, roles for users) would be a bonus, but I'm not sure whether bookshelf/knex supports this just now so it can be added later if it adds too much complexity. The main purpose of this feature, short term, is to provide for only returning titles/names/slugs for the autocomplete (#5343).

Note: I have started implementing this in #5518, and discovered that whenever you request an unknown column, the response returned is somewhat strange - the column name is surrounded in quotes. Specifying url for posts results in 2 fields being returned, the proper url attribute and one quoted like "url". I would suggest we need to upgrade both bookshelf & knex and if it still happens, raise this as a bug whilst also implementing a workaround in the toJSON method.

@ErisDS ErisDS added the affects:api Affects the Ghost API label Jul 25, 2015
ErisDS added a commit to ErisDS/Ghost that referenced this issue Aug 28, 2015
refs TryGhost#5601, TryGhost#5463, TryGhost#5343

- adds rudimentary support for a 'fields' parameter on browse requests
@ErisDS ErisDS mentioned this issue Aug 28, 2015
@ErisDS ErisDS mentioned this issue Oct 6, 2015
31 tasks
@ErisDS ErisDS modified the milestone: Public API v1 Oct 13, 2015
@ErisDS ErisDS mentioned this issue Oct 20, 2015
24 tasks
@ErisDS ErisDS closed this as completed in 3729078 Oct 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects:api Affects the Ghost API
Projects
None yet
Development

No branches or pull requests

1 participant