gpt4 book ai didi

node.js - 在 RESTful API 的上下文中,路由和端点之间有什么区别(如果有)?

转载 作者:搜寻专家 更新时间:2023-11-01 00:48:12 26 4
gpt4 key购买 nike

问题

我有一个可能相当简单的问题,但我无法找到有很好解释的答案:

Node.js 中开发的 RESTful API 上下文中,路由端点 之间有什么区别(如果有) >/Express 应用程序(但这些概念可能更广泛?!)?
(它是否以某种方式与 URL 相关?)

例子

例如,在这篇文章中:https://medium.com/@purposenigeria/build-a-restful-api-with-node-js-and-express-js-d7e59c7a3dfb我们可以阅读:

We imported express which we installed at the beginning of the course, app.get makes a get request to the server with the route/endpoint provided as the first parameter, the endpoint is meant to return all the todos in the database.

这些概念可以互换使用,这让我很困惑。
(请注意,我是 REST API、nodejs 和 express 的 100% 初学者,但我会尽力学习)。


编辑

按时间顺序来说,前两个答案让我更加困惑,因为它们完全对立。

最佳答案

这里有 3 个不同的概念:

  • 资源:{id: 42, type: employee, company: 5}
  • 路由:localhost:8080/employees/42
  • 端点:GET localhost:8080/employees/42

同一路由可以有不同的端点,例如 DELETE localhost:8080/employees/42。所以端点基本上是 Action 。

您还可以通过不同的路由访问相同的资源,例如 localhost:8080/companies/5/employees/42。所以路由是一种定位资源的方式。

关于node.js - 在 RESTful API 的上下文中,路由和端点之间有什么区别(如果有)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56075017/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com