静止端点的名称,该名称是最接近搜索的最接近匹配的名称
我的REST API在/items
上提供项目,并在/items?name =:name
上按确切名称提供项目。 API消费者需要另一个端点,该端点以“最相似”的名称提供单个项目,而不是在没有确切匹配的情况下404ing。命名此端点的最佳实践是什么?这两个替代方案对我来说似乎最合理:
-
/items/近距离?名称=:name
-
/items?name =:name& amp; amp; match = fuzzy
这些项目也可用通过/items/:ID
的精确数值ID匹配。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有真正的正确或错误的方法来做您在这里需要的事情,但是我要指出的是,端点URL应该是描述资源的名词,因此我不会使用第一个选项,因为我不认为
/项目/最近的匹配
在这里表示资源。我喜欢第二个替代方案,在其中您要按名称过滤这些项目,并指定比赛需要如何“严格”。
There's no real right or wrong way of doing what you need here, but I would point out that the endpoint URL should be a noun that describes a resource, so I wouldn't go with the first option since I don't think
/items/closest-match
is representing a resource here.I like the second alternative, where you're filtering the items by name and also specifying how "strict" the match needs to be.