starlette-jsonapi icon indicating copy to clipboard operation
starlette-jsonapi copied to clipboard

Filtering

Open LeafyLappa opened this issue 4 years ago • 3 comments

Hi!

I am unable to find any information on how to correctly implement filtering of resources. API reference seems to have nothing on this, neither do the public contracts in the class BaseResource from resource.py. I would assume that this feature is not implemented as of yet but it doesn't even seem mentioned anywhere in this project unless I'm missing something.

For reference, I have this resource "apps" and clientside I'd like to be able to fetch a single app either by its id or its (unique still) name. I presume the best way to achieve this in JSON:API is by applying a filter: /apps?filter[name]=name. I'm interested whether I can implement this functionality using this framework.

LeafyLappa avatar Aug 05 '21 09:08 LeafyLappa

Turns out for my case I can use request.query_params, whose method getlist with "filter[name]" as argument gives me what I need. Feels like a hack though.

LeafyLappa avatar Aug 05 '21 09:08 LeafyLappa

Hello @LeafyLappa !

Indeed, the framework does not come with a filtering implementation, mostly because it's really hard to come up with an abstraction that would work regardless of the data layer under the hood.

That said, I'm pretty sure we can build a helper method to parse the filter[*] query parameter and offer something easier to work with.

PRs are welcome if you'd like to try this yourself.

vladmunteanu avatar Aug 05 '21 17:08 vladmunteanu

Sure! I will likely code something for my project, will see if I have the time to make it reusable.

LeafyLappa avatar Aug 05 '21 21:08 LeafyLappa