0

What is the best practice to include related resources in the search query?

my resources are:

/projects
/participants
/questions
/questionAnswers

the query would be something like: get all participants who are:

- between the age of 20 and 40 and,
- male and,
- selected answer X of question y 

would it be something like

/participants?search=gender:male,age>=20,age<=40,question:x,answer:y

Is there a better or a standard way for this type of queries?

zoro74
  • 151
  • 12
  • Personally, I'd rather use application/x-www-form-urlencoded and send it as POST. That's a personal opinion and I could be wrong. Maybe this will help https://stackoverflow.com/questions/4024271/rest-api-best-practices-where-to-put-parameters – Francis Zabala Sep 14 '17 at 06:54
  • Maybe [GraphQL](https://github.com/facebook/graphql) would be more feasible for your case? – Kim Sep 14 '17 at 08:11

1 Answers1

0

you can use object serialization & filters. like:

/participants?filter={gender={male}, age={between={20, 40}}, question={x}, answer={y}}

for given example with:

  • gender = male, female
  • age = (1...99) OR between={start, end} OR till={end} OR from={start} etc..

in this case, you have the possibility to filter more specific and/or combined. A combination for example:

/participants?filter={gender={male, female}, age={21,22, 23, from={40}}, question={x}, answer={y}}

result: gender male and female with age 21, 22, 23 and from 40 till 99 (or what you want)

MAck
  • 1
  • 1