Hello friends, I have successfully created my first REST API and I can list out all persons and get a specific person like so : http://mysite.com/rest/persons/2
I have followed the official documentation and my controller is extending the modRestController, and I have checked the class on github.
So to my question: what is the syntax for querying on a specific field?
For example to fetch all persons with firstname «Roger». I would expect something like this:
Thank you for your quick reply, I’m not at my computer now but will try that later. But assumning I want to query all persons with firstname «Roger» and say city=Oslo, and perhaps order the result on another field again… is that possible, or will it be necessary to write some custom code? The documenation IMHO is quite sparse on this topic, and I have spent a considerable amount of time scouring the forums.
Edit: ah I think I understand now. If I understand it correctly I can add as many query-params as I need using the same pattern as for addSearchQuery(), and then just write my own xPDO queries.
Correct?
For the ordering you should be able to use ?sort=field&dir=desc out of the box.
From what I can tell, when you want to search for two different search values, then you have to override the function addSearchQuery in your own class.
Thanks again, much appreciated. I also found this:
/**
* Allows manipulation of the query object before the COUNT statement is called on listing calls. Override to
* provide custom functionality.
*
* @param xPDOQuery $c
* @return xPDOQuery
*/
protected function prepareListQueryBeforeCount(xPDOQuery $c) {
return $c;
}
Probably here I can populate searchFields… think I will just have do some testing. Regarding documenation: I would be happy to contribute improving it regarding this specific topic.