Cake 3.5 REST - How customize search


#1

Is it possible to refine queries using cake API or ID is the only option? Can I customize routes to enable that?

I am able to search by ID like ttp://localhost/recipes/1.json. Can the search be refined somehow?


#2

If you want people to be able to look up certain records by certain keys or columns, using the URL, then you can use the existing routes and program your controllers to do the work the way you want to. You will need a view (*,ctp) for each function.
For instance, you can look up Articles via their ID but also via their slug. Create 2 functions:

public function view_by_slug($slug = null) {

and

public function view_by_id($id = null) {

Each function is then programmed to look up the respective record based on a different column, each in the same manner.

You can then look up an article by either;

http://localhost/articles/view_by_slug/first-post

or

http://localhost/articles/view_by_id/1

Good luck.