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

Is there support for field selection parameters? #193

Open
igorsantos07 opened this issue Jun 12, 2018 · 8 comments
Open

Is there support for field selection parameters? #193

igorsantos07 opened this issue Jun 12, 2018 · 8 comments
Labels

Comments

@igorsantos07
Copy link
Contributor

I'm researching API packages for Laravel and was wondering if the missing doc page called "sparse fieldsets" is related to the ?fields parameter specified on the JSON-API, that allows a request to only receive a number of specified fields on the response.

On the same topic, is sorting supported or a planned feature?

Bottom-line: what's "to be done", the docs or the feature itself? :)

@lindyhopchris
Copy link
Member

The @todos in the docs indicate where I need to write docs, but the features do work. If a feature doesn't work there'll be an issue linked to a milestone.

The fields parameter is fully support so if you send it with a request it will work. You may need to set the allowedFieldSetsType on your validators class, as per this doc block:
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Query/ChecksQueryParameters.php#L64-L82

@mathieufrh
Copy link

First, I really appreciate this project. It's a must have for every laravel devs who try to create and maintain standardized Json API.
I was wondering how the felds parameter actually works ? I guess I can list the fields of the resource that I want to be included in the response. But can I also choose the fields of the related resources ? I mean, If I fetch a single post with all it's related comments, can I choose the comments fields that I want ?

@lindyhopchris
Copy link
Member

Yes the implementation complies with the spec:
https://jsonapi.org/format/#fetching-sparse-fieldsets

Those docs give this example:

GET /articles?include=author&fields[articles]=title,body&fields[people]=name HTTP/1.1
Accept: application/vnd.api+json

In that the fields[articles] sets the fields for the articles resource, the fields[people] sets the fields for the people resource.

So yes, you can ask for the fields of the primary resource that is being requested plus the included resources.

@mathieufrh
Copy link

Thank you very much ! This is awesome !

@myfbone
Copy link
Contributor

myfbone commented Dec 19, 2019

Hi! I believe that you should consider updating this part of docs, because @todos in these docs is somehow confusing. You can at least write that this feature is implemented. Thanks!

myfbone added a commit to myfbone/laravel-json-api that referenced this issue Dec 19, 2019
@lironesamoun
Copy link

I would like to know (as it does not seem to work) if it's possible to do get a specific field on a relationship link.

For example:

http://127.0.0.1:8000/api/v1/assets/27/histories?fields[assets]=id
By doing this, I still have all the attributes and I wanted to get just a specific field.

@ben221199
Copy link
Contributor

@lilouch I remember something like using a dot for that. If you have a relationship assets with a field id on each asset, I think you should try assets.id.

@lindyhopchris
Copy link
Member

@lilouch it's because you're only requesting the id field. If you only want the resource identifiers of a relationship, you should use this endpoint:

GET http://127.0.0.1:8000/api/v1/assets/27/relationships/histories HTTP/1.1
Accept: application/vnd.api+json

The fields will work on the endpoint that you're using (/api/v1/assets/27/histories) but the fields should be attributes and/or relationships. That will return sparse fieldsets.

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

No branches or pull requests

6 participants