开发者

In what circumstance should I redirect the client to a more accurate URI

We have a RESTFul webservice that returns a list of persons.

/person/list

However, the business wants to return only "active" persons. i.e. persons created after 开发者_如何学Go2009.

I'm proposing to redirect(307?) /person/list to /person/list?createdAfter=2009 since that is a more accurate representation of the resource. Does it make sense? If not, why not?


In my opinion, the URL /person/list should return an unfiltered list. To get the filtered list, you should have to explicitly specify createAfter=2009.

I say this thinking of down the road. What if you have an application that does actually want all of the users? What if you have a bunch of old code depending on /person/list magically redirecting to the filtered version and you for some reason need to change the URL /person/list to actually be the unfiltered version? Then your old code just broke because it would be pulling all users.

I would go with 1 of two approaches:

1) Do not redirect. Just have /person/list silently imply only active persons. In this situation, to get the non active, you would have to actually request /person/list?all or /person/list?includingInactive or something (hopefully you get the point -- you have to explicitly request the disabled ones)

2) Actually use the URL with ?createAfter=2009 in your applications.

I would probably go with the first option. It lets you keep the logic of what an active person is and isn't in your webservice instead of in applications, and it means the meaning of the URL will never change (just /person/list would be understood to be a list of only active persons).


What's wrong with using /person/list/active? You know that active is created after 2009 but the definition could change.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜