简体   繁体   English

REST API用于复杂查询

[英]REST API for Complex Queries

How do I implement count, group by, and other commonly used SQL constructs using GET REST API calls and still adhering to good standards? 如何使用GET REST API调用并仍然遵循良好标准来实现计数,分组依据和其他常用SQL构造? I haven't seen any documentation that describes how to do this. 我还没有看到任何描述该操作方法的文档。 Are there any standards already in place? 是否有任何标准? Any help would be appreciated. 任何帮助,将不胜感激。 Thanks. 谢谢。

From the other answer, I think you are looking for this: 从其他答案中,我认为您正在寻找的是:

POST /books/search

    {
        "keywords": "...",
        "yearRange": {"from": 1945, "to": 2003},
        "genre": "..."
    }

There is nothing un-RESTful about this endpoint. 没有任何关于此端点的RESTful。 It accepts data (entity) in the form of the request body. 它接受请求主体形式的数据(实体)。 That data is the Search Criteria - a DTO like any other. 这些数据就是“搜索条件”-像其他任何DTO一样。 This endpoint produces a resource (entity) in response to the request: Search Results. 该端点根据以下请求生成资源(实体):搜索结果。 The search results resource is a temporary one, served immediately to the client, without a redirect, and without being exposed from some other canonical url. 搜索结果资源是一个临时资源,可立即提供给客户端,无需重定向,也不会暴露于其他一些规范的URL。

It's still REST, except the entities aren't books - the request entity is book search criteria, and the response entity is book search results. 它仍然是REST,只是实体不是书籍-请求实体是书籍搜索条件,响应实体是书籍搜索结果。

Look at this answer for more details: https://stackoverflow.com/a/31984477/37083 查看此答案以获取更多详细信息: https : //stackoverflow.com/a/31984477/37083

Using this structure you can easily expand the search with other complex items 使用此结构,您可以轻松地扩展其他复杂项目的搜索

POST /books/search

    {
        "keywords": "...",
        "yearRange": {"from": 1945, "to": 2003},
        "genre": "...",
        "groupby": "year",
        "countby": "keywords"
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM