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
In reply to Complex filter queries in a REST API by martell
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |