biosustain / potion

Flask-Potion is a RESTful API framework for Flask and SQLAlchemy, Peewee or MongoEngine
http://potion.readthedocs.io
Other
487 stars 51 forks source link

Filter / search by any field? #147

Closed b-ryan closed 6 years ago

b-ryan commented 6 years ago

I want to provide a way to search by multiple fields at once. Let's say in the books / authors example in the docs I wanted to make a request like:

http :5000/author search=='xyz'

The endpoint could return any results where the author has 'xyz' in their first or last name. Maybe it might even return authors who have a book with 'xyz' in the title.

Is this possible?

lyschoening commented 6 years ago

Yes, that's possible. You'll need to override the default instances function with your own search implementation: https://github.com/biosustain/potion/blob/master/flask_potion/resource.py#L263-L265

A simpler approach would be to add a custom search endpoint, e.g. http :5000/author/search q=='xyz'.

b-ryan commented 6 years ago

Excellent - thanks