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

前端 未结 3 1039
攒了一身酷
攒了一身酷 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条回答
  •  梦毁少年i
    2021-02-15 14:29

    Stripe has one of the most respected APIs.

    They use a separate parameter for each operator separated with a dot.

    For example, to search on created date:

    /charges?created.gt=
    /charges?created.gte=
    /charges?created.lt=
    /charges?created.lte=
    

    In your case you could do something like:

    /students?grade.gt=8&grade.lt=8
    

    Or even add another operator for not:

    /students?grade.not=8
    

提交回复
热议问题