martell has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
I would like to hear your thoughts on how to approach complex filtering queries in a REST API.
I've built in the past an internal company REST API in Catalyst using Catalyst::Controller::REST and DBIx::Class for database access. At the time there was little need for filtering on the request except for some trivial cases like GET http://../collection/?name=some_value or GET http://../collection/?date_from=20200101&date_to=20201231. Those cases I've built with a naive approach to translate the parameters towards valid search queries like $c->model(..)->search([shoot_date => ['-and', {'>=', $shoot_date_from},{'<=', $shoot_date_to} ]]);
Now the question has been asked to foresee more complex cases of filtering where several criteria can be combined. So, I was wondering what is a good strategy to build a more flexible way of encoding a filter query in the GET request and translate it into the appropriate SQL statements.
I've been searching a bit and i find some stuff on building flexible sql queries in DBIx::Class with SQL::Abstract. And if find some strategies to encode queries into an uri using for example Apache Lucene syntax, for exeample GET http://../collection?q=name:(value1 value2 value3) and date:[20200101 TO 20201231], and validate and translate the query by using Lucene::QueryParser. But I don't find anything that connects the two sides.
So, are there any good approaches to encode a flexible query into an uri, easily decode the query and encode it into a SQL statement usable to retrieve the records?
Kind regards
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Complex filter queries in a REST API
by bliako (Abbot) on Mar 25, 2021 at 11:25 UTC | |
by hippo (Archbishop) on Mar 25, 2021 at 12:23 UTC | |
by bliako (Abbot) on Mar 25, 2021 at 15:08 UTC | |
by martell (Hermit) on Mar 26, 2021 at 11:29 UTC | |
by bliako (Abbot) on Mar 26, 2021 at 15:52 UTC | |
by Anonymous Monk on Mar 25, 2021 at 14:10 UTC | |
Re: Complex filter queries in a REST API
by perlfan (Parson) on Mar 25, 2021 at 17:09 UTC | |
by martell (Hermit) on Mar 26, 2021 at 11:38 UTC | |
Re: Complex filter queries in a REST API
by vincent_veyron (Beadle) on Mar 25, 2021 at 16:40 UTC | |
by martell (Hermit) on Mar 26, 2021 at 11:46 UTC |