路由和端点之间的区别? [英] Difference between route and endpoint?
问题描述
我有一个可能很简单的问题,但是我找不到很好的解释的答案:
I have a probably rather simple question, but I'm unable to find an answer with nice explanations:
什么是在 Node.js $ c $中开发的RESTful API上下文中,路由和端点之间的差异(如果有) c> /
Express
应用程序(但是这些概念可能更广泛?!...)?
(它与URL有某种联系吗? )
What is the difference (if any) between a route and an endpoint in the context of a RESTful API developed within a Node.js
/ Express
application (but these concepts may be broader?!...)?
(Does it relate to URLs in some way?)
例如,在本文中: https://medium.com/@purposenigeria/build-a-restful- api-with-node-js-and-express-js-d7e59c7a3dfb 我们可以看到:
For example, in this article: https://medium.com/@purposenigeria/build-a-restful-api-with-node-js-and-express-js-d7e59c7a3dfb we can read:
我们导入了在开始时安装的Express当然,app.get使用提供的 route / endpoint 作为第一个参数向服务器发出get请求,该终结点旨在返回所有
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.
这些概念可互换使用,这让我感到困惑。
(请注意,我我是100%使用REST API,nodejs和express的初学者,但我会尽力学习。)
These concepts are used interchangeably, which makes me confused.
(please note that I'm a 100% beginner with REST API, nodejs and express but I try to do my best to learn).
编辑:
这两个答案使我更加困惑,因为它们完全是对立的。
Edit:
The two first answers make me even more confused as they are perfectly antagonistic.
推荐答案
这里有3个不同的概念:
3 different concepts here:
- 资源:
{id:42,类型:员工,公司:5}
- 路由:
localhost:8080 / employees / 42
- 端点:
GET localhost :8080 / employees / 42
- Resource:
{id: 42, type: employee, company: 5}
- Route:
localhost:8080/employees/42
- Endpoint:
GET localhost:8080/employees/42
对于同一路由,您可以有不同的终结点,例如删除本地主机:8080 / employees / 42
。因此,端点基本上就是动作。
You can have different endpoints for the same route, such as DELETE localhost:8080/employees/42
. So endpoints are basically actions.
您还可以通过不同的路径(例如 localhost:8080 / companies / 5 / employees / 42)访问相同的资源
。因此,路由是一种查找资源的方法。
Also you can access the same resource by different routes such as localhost:8080/companies/5/employees/42
. So a route is a way to locate a resource.
这篇关于路由和端点之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!