问题描述
我有一点困难,设计一个网址给其他服务,可以处理基于分页为一个类型的操作或请求比高于运营商为另一种类型的操作,或大或小的客户请求。例如:
I am having a bit of difficulty designing a url for a rest service that can handle requests for customers based on pagination as one type of operation or requesting greater than or less than operators as another type of operation. For example:
分页:
GET /customers/0/100
这将得到100名顾客第0页。
This will get 100 customers for page 0.
大于/小于:
我还需要一个URL设计获得具有大于n的ID的客户(例如,可以说716)。你将如何体现大于或小于的网址。我必须要牢记的字符>和< URL中的非法。我觉得这个网址设计看起来很奇怪:
I also need a URL design to get customers that have an id greater than n (e.g. lets say 716). How would you incorporate "greater than" or "less than" in a url. I have to bear in mind that characters ">" and "<" are illegal in urls. I think this url design looks odd:
GET /customers/greaterthan/716
GET /customers/lessthan/716
我不能使用范围内,将上述指定分页模式冲突,是不是在任何情况下,例如一个很好的解决方案:
I can't use a range as that would conflict with the pagination pattern specified above and is not a nice solution in any case e.g.:
GET /customers/716/999999999999
GET /customers/0/716
我敢肯定,我失去了一些东西很明显 - 没有任何人有一个更好的解决方案。
I'm sure that I'm missing something obvious - does anyone have a better solution?
推荐答案
的分页的 GREATERTHAN 的和的每种不超过的,声如查询参数给我,既然你是查询使用这些参数你的资源。
所以,你应该这样做:结果
/客户?页= 1 结果
或 /客户页= 1&放大器; GT = 716 结果
或 /客户页= 1&放大器; GT = 716安培; LT = 819 结果
你甚至可以限制网页大小: /客户页= 1&放大器; GT = 716安培; LT = 819安培; maxpagesize可= 100
Pagination, greaterthan and lessthan, sound like query parameter to me, since you are queries your resource with these parameters.So you should do something like:
/customers?page=1
Or /customers?page=1>=716
Or /customers?page=1>=716<=819
You can even limit size of page: /customers?page=1>=716<=819&maxpagesize=100
的 GT 的代表大于(相同的XML转义)结果
的 LT 的代表小于
gt stands for greater than (same as in xml-escaping)
lt stands for less than
这篇关于REST网址设计为大于,小于操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!