REST url for resource collection, which filters resource by attribute not equal to a given value

前端 未结 3 1037
攒了一身酷
攒了一身酷 2021-02-15 13:47

How to design REST url for resource collection, which filters resource by attribute not equal to a given value?

For example, to get the students in 8th grade, we use

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-15 14:50

    What I am thinking of doing is including the operator as part of the argument, delimited from the value. I would also define non-symbolic operators to avoid the need for ugly URL-encoding or confusion with the equals sign after the parameter name. For your example, this would be something like this for students not in grade 8:

    GET /students?grade=neq|8
    

    Students in grades > 8 would be:

    GET /students?grade=gt|8
    

    Students between grades 8 and 10 (inclusive):

    GET /students?grade=gte|8,lte|10
    

    This approach can be extended to other filterable fields without the need to add additional parameters to modify the way each field is filtered.

提交回复
热议问题