Querystring in REST Resource url

前端 未结 10 1704
天命终不由人
天命终不由人 2020-11-28 19:34

I had a discussion with a colleague today around using query strings in REST URLs. Take these 2 examples:

1. http://localhost/findbyproductcode/4xxheua
2. ht         


        
10条回答
  •  执笔经年
    2020-11-28 19:47

    In typical REST API's, example #1 is more correct. Resources are represented as URI and #1 does that more. Returning a 404 when the product code is not found is absolutely the correct behavior. Having said that, I would modify #1 slightly to be a little more expressive like this:

    http://localhost/products/code/4xheaua
    

    Look at other well-designed REST APIs - for example, look at StackOverflow. You have:

    stackoverflow.com/questions
    stackoverflow.com/questions/tagged/rest
    stackoverflow.com/questions/3821663
    

    These are all different ways of getting at "questions".

提交回复
热议问题