OpenRasta - 为列表资源提供过滤、排序和分页

发布于 2024-12-23 10:03:47 字数 446 浏览 3 评论 0原文

我们正在使用 OpenRasta 创建一个 REST API,除了对所有资源进行常规 GET、POST、PUT 和 DELETE 之外,我们还对具有复数名称的资源提供 GET。因此,API 的使用者可以对 User 执行 GET、POST、PUT 和 DELETE,还可以对 Users 执行 GET,这将返回 List 。现在我们希望客户端能够根据其属性对其进行过滤和排序,并允许支持分页以分页表格格式显示数据。

虽然,我查看了 WCF 数据服务工具包 主页,看起来它可能很有用,但在查看了博客文章之后和入门页面,我无法理解如何使用它来解决 OpenRasta 中的问题。

或者还有其他更简单的事情我可以做吗?

We are creating a REST API using OpenRasta and apart from regular GET, POST, PUT and DELETE on all resources, we are also providing GET on resources with plural names. So a consumer of the API can GET, POST, PUT and DELETE on User and also perform GET on Users which will return List<Users>. Now we want the clients to be able to filter and sort it by it's properties and allow to support paging for showing data in paged tabular formats.

Although, I looked at WCF Data Services Toolkit home page and looks like it can be useful but after looking at blog posts and Getting Started page, I couldn't understand how I can use it to solve my problem in OpenRasta.

Or is there anything else simpler that I can do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弃爱 2024-12-30 10:03:47

OR 不支持 OData 之类的功能,主要是因为它会导致系统非常不稳定。

如果 /users 是“用户列表”,那么它与 /users/1(用户的第一页)或 /users/byName/1(按名称排序的用户的第一页)是不同的资源。

当然,您可以通过注册具有查询参数的 URI 来轻松实现所有这些,因为这些参数是可选的

.AtUri("/users?page={page}&filter={filter}

并且您的处理程序可以如下所示

public List<User> Get(int page = 0, string filter = null) { ... }

OR doesn't support stuff like OData for that functionality, mainly because it leads to very unrestful systems.

If /users is "the list of users", then it is a different resource than /users/1 (the first page of users) or /users/byName/1 (the first page of users ordered by name).

You can of course implement all this easily by registering a URI that has query parameters, as those are optional

.AtUri("/users?page={page}&filter={filter}

And your handler can look like

public List<User> Get(int page = 0, string filter = null) { ... }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文