REST风格的设计:分页集合 [英] RESTful Design: Paging Collections

查看:1721
本文介绍了REST风格的设计:分页集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计需要分页(每x)的一个REST API从服务器端强制执行。

I am designing a REST api that needs paging (per x) enforces from the server side.

什么是正确的方式页面通过资源的任何集合:

What would be the right way to page through any collection of resources:

选项1:

GET /resource/page/<pagenr>
GET /resource/tags/<tag1>,<tag2>/page/<pagenr>
GET /resource/search/<query>/page/<pagenr>

选项2:

GET /resource/?page=<pagenr>
GET /resource/tags/<tag1>,<tag2>?page=<pagenr>
GET /resource/search/<query>?page=<pagenr>

如果1,我应该用GET /资源呢?重定向到/资源/页/ 0,有些错误答复或完全相同的/资源/页/ 0回复没有重定向?

If 1, what should I do with GET /resource? Redirect to /resource/page/0, reply with some error or reply with the exact same as /resource/page/0 without redirecting?

推荐答案

有什么URI看起来不是最重要的组成部分。什么,你应该不是想着是怎么回事psented用户$ P $。一个页面应该例如有一个链接到下一个页面,另一个链接到previous页面(如果有的话)。看看 RFC 5005饲料分页和存档

What the URI looks like is not the most important part. What you should be thinking about instead is how it is presented to the user. A page should for example have a link to the "next" page and another link to the "previous" page (if there is one). Take a look at RFC 5005 Feed Paging and Archiving

这篇关于REST风格的设计:分页集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆