What is the best option to separate REST query search terms from options? -
let's have rest api /cars. if get /cars cars (if allowed). if want cars red, might get /cars?color=red.
now let's assume want sort them, options ascending vs descending.
get /cars?color=red&sort=asc
the problem here sort not search term, option. makes difficult server differentiate between search terms color=red , search options sort=asc.
it bad way design api, since 1 day might want use sort field can search on (as opposed option).
how people recommend constructing search api? here options have found:
- leave is, knowing fields are, definition, options , not terms.
- special flags search terms, e.g.
search.color=red&search.year=2010&sort=asc - special flags search options, e.g.
color=red&year=2010&option.sort=asc - special flag whole thing, e.g.
search=[color=red&year=2010]&sort=asc(with[..]section url encoded)
thoughts?
how use of odata http://www.odata.org/documentation/odata-version-2-0/uri-conventions/
odata v2
get /cars?$orderby=rating asc /cars?$filter=color eq red /cars$filter=color eq red , year eq 2000&$skip=2&$top=2&$orderby=category/rating desc or check odata library , uri syntax of version 3 or 4. odata kind of standard , supported in .net , in java , javascript. there established libraries.
Comments
Post a Comment