开发者

RESTful: Best URI practice in parameterized request of data?

开发者 https://www.devze.com 2023-01-02 11:48 出处:网络
Trying to get the grips of best URI practice in RESTfulness... Let\'s say that /service/user.xml returns an xml with all users data

Trying to get the grips of best URI practice in RESTfulness... Let's say that

  • /service/user.xml returns an xml with all users data
  • /service/user/1.xml returns an xml with data for user id 1

What if I want to get just the email address of the 开发者_如何学Pythonuser(s)?

  • /service/user.xml?par=email or /service/user/email.xml for all users?
  • /service/user/1.xml?par=email or /service/user/email/1.xml for user id 1?

Regards / Jonas


In my opinion, it makes sense if you think of it as constantly narrowing down your search. You first start with a huge collection of "objects", and refine, becoming more and more specific..

So it goes:

service -> choosing a particular user -> specify that user id -> specify what you need from them -> specify in what format you want that information

or service/user/:id/email.:format

Alternatively, it wouldn't be wrong to say service/user/:id.:format?parameter=:param, if it didn't make sense to create a whole route for something that is potentially trivial.

I think ultimately these specifics don't always have "the best way", but rather several "recommended ways", and one of them will suit you most.

You might find these links to be interesting.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号