Use Queryparam or Change Resopurce path

asharma377
Participant V

I have came across situation where i want to do following operations on sketchboard. where i can add new sketchboard, getsketchboard, delete, update(CRUD) as well as also get some popular sketchboards.


All of these operations are pointing to a different target endpoint and a target URL.

I have one basepath

/sketchboard - For all CRUD operations pertaining to sketchboard

I am evaluating what is the best way to implement popular sketch boards. Should i use the path

/sketchboard/popular or should i use queryparam /sketchboard?popularBoard=true.

Though in examples of best practices it is mentioned that we should use queryparams to filter out dogs.

/dogs?eyes=red etc. But, here i have a different target endpoint and url. will it be fine to map to different target on the basis of queryparam. Any thoughts?

1 4 354
4 REPLIES 4

faijahmad
Participant V

My point of view, you should use this as Query Param like

?sort=popular

In future you might other values like hottest, MostViewed and many more. Those you can pass as queryparam rather than creating always new resource path.

thanks a lot for your views.

These sorts of decisions are always fun. I would take an outside in approach and consider the new API design rather than the backend implementation.

Agree with @Faij Ahmad its generally not good to add concrete paths like "popular" to serve as what I call "convenience searches".

GET /sketchboards?rating=popular

If popular is one of the valid values for rating. Similarly...

GET /sketchboards?stars=4

I wouldn't use sort=popular because sort generally implies the field to sort the results on.

GET /sketchboards?sort=stars&direction=desc

would sort the results by stars.

Thank you Kurt !