静止端点的名称,该名称是最接近搜索的最接近匹配的名称

发布于 2025-02-07 09:40:09 字数 353 浏览 3 评论 0 原文

我的REST API在/items 上提供项目,并在/items?name =:name 上按确切名称提供项目。 API消费者需要另一个端点,该端点以“最相似”的名称提供单个项目,而不是在没有确切匹配的情况下404ing。命名此端点的最佳实践是什么?这两个替代方案对我来说似乎最合理:

  • /items/近距离?名称=:name
  • /items?name =:name& amp; amp; match = fuzzy

这些项目也可用通过/items/:ID 的精确数值ID匹配。

My REST API serves items at /items, and items by exact name at /items?name=:name. An API consumer needs another endpoint that serves the single item with "most similar" name, instead of 404ing when there is no exact match. What is the best practice for naming this endpoint? These two alternatives seem most reasonable to me:

  • /items/closest-match?name=:name
  • /items?name=:name&match=fuzzy

The items are also available by exact numerical ID match at /items/:id.

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

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

发布评论

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

评论(1

萌酱 2025-02-14 09:40:09

没有真正的正确或错误的方法来做您在这里需要的事情,但是我要指出的是,端点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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文