设计 RESTful API 时如何正确公开布尔搜索函数?
我正在为搜索功能设计一个 RESTful API,如下所示:
http://example.com/books/?author=John+Smith&title=Brain+Surgery+For+Dummies
看着这个 URI,我不能立即知道客户端正在执行哪两个查询:
a) John Smith 的所有书籍,以及所有题为“Brain Surgery for Dummies”的书籍
b) 所有版本的“Brain Surgery for Dummies”作者:约翰·史密斯。
我如何重新设计 URI 以使其更加明确?
I'm designing a RESTful API for a search function that looks something like this:
http://example.com/books/?author=John+Smith&title=Brain+Surgery+For+Dummies
Looking at this URI, I don't immediately know which these two queries the client is performing:
a) all books by John Smith, plus all books entitled "Brain Surgery for Dummies"
b) all editions of "Brain Surgery for Dummies" authored by John Smith.
How might I redesign my URIs to make this more explicit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我从示例中了解到,“作者”是一种资源:
或
在作者的图书集中搜索图书
或
在图书集中搜索图书:
在任何一种情况下搜索都意味着该书的确切名称/标题未知,并且搜索可能会返回多个物品,尽管特定的书本身也是一种资源。在这种情况下,您需要为书籍定义 URI:
书籍资源:
As I understand from examples "author" is a resource:
OR
Search book in the author's books collection
OR
Search book in the books collection:
Searching in either case means that exact name/title of the book is not known and search can possibly return multiple items, though particular book by itself is a resource too. In this case you need to define URI for book:
Book resource: