Querystring in REST Resource url

前端 未结 10 1729
天命终不由人
天命终不由人 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 20:01

    IMO the path component should always state what you want to retrieve. An URL like http://localhost/findbyproductcode does only say I want to retrieve something by product code, but what exactly?

    So you retrieve contacts with http://localhost/contacts and users with http://localhost/users. The query string is only used for retrieving a subset of such a list based on resource attributes. The only exception to this is when this subset is reduced to one record based on the primary key, then you use something like http://localhost/contact/[primary_key].

    That's my approach, your mileage may vary :)

提交回复
热议问题