Restful api routes naming convention for specific filter

时间:2017-06-15 09:51:41

标签: rest api naming-conventions api-design restful-url

I have in database some "Evaluation" which have foreign key nullable to "Category"

So in standard Rest route I've done this 2 routes :

  • GET /api/categories/{category_id}/evaluations (for a specific category)

  • GET /api/evaluations (for all evaluations with or without category)

My question is for the GET on evaluations which DON'T have a category (named "basic" evaluation), how should I name it :

  • GET /api/evaluations/basic
  • GET /api/basic/evaluations
  • GET /api/categories/evaluations
  • GET /api/categories/basic/evaluations

?

1 个答案:

答案 0 :(得分:0)

鉴于basic听起来像评估类型,您可以通过筛选查询字符串来实现此目的:

GET /api/evaluations?type=basic

当然,这也可以扩展到支持更多过滤,以及排序或分页