vendredi 27 novembre 2020

Designing endpoints for multiple filters

I am curious if there is a better way to handle an advanced filter design. I have an API for a music catalog that allows users to search for tracks based on the following criteria (if nothing is provided then it just returns a paginated result of all tracks ordered by added date)

that means a base endpoint of something like http://www.myapi.com/api/tracks Then I offer the following parameters to allow for advanced filtering based on multiple things if they choose to do so. If a parameter is not provided then it is not included in the query at all.

Artist Name / Song Title

Genre(s)

Key(s)

BPM Range

Version Type(s)

For example, you could search for Rock songs that are in key 2A, and all songs that meet that criteria would be returned. The endpoint would then look something like this:

http://www.myapi.com/api/tracks?genres=ROCK&keys=2A

My question is that in designing something like this is there any other approach than setting up your endpoint to basically brute force through all of the possible request param combinations and having a separate query for basically each combo?

When I think of this I think of something like Linkedin's advanced filter ... surely they can't brute force that kind of thing, it would be terrible to maintain and scale. How is that kind of functionality usually implemented in production systems?

Aucun commentaire:

Enregistrer un commentaire