简体   繁体   English

RESTful查询API设计

[英]RESTful query API design

I want to ask what is the most RESTful way for queries, I have this existing API 我想问问最RESTful的查询方式是什么,我有这个现有的API

/entities/users?skip=0&limit=100&queries={"$find":{"$minus":{"$find":{"username":"markzu"}}}}

Easily the first parts of the query, skip and limit are easily identifiable however I find the "queries" part quite confusing for others. 很容易确定查询的第一部分, skiplimit ,但是我发现“查询”部分使其他人感到困惑。 What the query means is to 查询的意思是

Find every User minus Find User entities with username 'markzu' 查找每个用户减去使用用户名“ markzu”的查找用户实体

The reason it is defined this way is due to the internal database query behavior. 之所以这样定义,是因为内部数据库查询行为。 Meaning in the NoSQL database we use, the resource run two transactional queries, first is to find everything in the User table minus a find User with a username that was specified (similar to SQL) -- boolean operations. 在我们使用的NoSQL数据库中,该资源运行两个事务查询,首先是查找User表中的所有内容,然后减去具有指定用户名(类似于SQL)的find User布尔操作。 So in other words, the query means, "fetch every User except username 'markzu' " 因此,换句话说,查询的意思是“获取除用户名'markzu'外的每个用户

What is the proper way to define this in RESTful way, based on standards? 基于标准以RESTful方式定义此方法的正确方法是什么?

What is the proper way to define this in RESTful way, based on standards? 基于标准以RESTful方式定义此方法的正确方法是什么?

REST doesn't care what spelling you use for resource identifiers, so long as your choice is consistent with the production rules defined in RFC 3986 . 只要您的选择与RFC 3986中定义的生产规则一致,REST就不会在意您对资源标识符使用什么拼写。

However, we do have a standard for URI Templates 但是,我们确实有URI模板的标准

A URI Template is a compact sequence of characters for describing a range of Uniform Resource Identifiers through variable expansion. URI模板是紧凑的字符序列,用于通过变量扩展描述一系列统一资源标识符。

You are already aware of the most familiar form of URI template -- key-value pairs encoded in the query string. 您已经知道URI模板最熟悉的形式-查询字符串中编码的键-值对。

?skip=0&limit=100&username=markzu

That's often a convenient choice, because HTML understands how to process forms into url encoded queries. 这通常是一个方便的选择,因为HTML知道如何将表单处理为url编码的查询。

It doesn't look like you need any other parameters, you just need to be able this query from others. 看起来您不需要任何其他参数,只需要能够从其他人那里获得此查询即可。 So a perfectly reasonable choice might be 因此,一个完全合理的选择可能是

/every-user-except?skip=0&limit=100&username=markzu

It may help to think "prepared statement", rather than "query". 考虑“准备的语句”而不是“查询”可能会有所帮助。

The underlying details of the implementation really shouldn't enter into the calculation at all. 实际上,根本不应该将实现的基本细节纳入计算。 Your REST API is a facade that makes your app look like an HTTP aware key value store. REST API是一个外观,使您的应用看起来像HTTP感知的键值存储。

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

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