简体   繁体   English

API 网关是否只有一个端点?

[英]Do API gateways only have a single endpoint?

I'm learning about micro services and API gateways.我正在学习微服务和 API 网关。 Some articles mention that api gateways only have one endpoint.一些文章提到 api 网关只有一个端点。 Is that correct?那是对的吗?

Let's say my e-commerce page makes 2 calls, /products and /users to get products and user data, and they are in a Product service and User service respectively.假设我的电子商务页面进行了 2 次调用,/products 和 /users 以获取产品和用户数据,它们分别位于产品服务和用户服务中。

Does my client make calls to api.com/products and api.com/users separately?我的客户是否分别致电 api.com/products 和 api.com/users? Or does it do api.com/exec?endpoint=users (or something like this)?还是 api.com/exec?endpoint=users(或类似的东西)?

From the context, it seems that the endpoint here is the domain - api.com.从上下文来看,这里的端点似乎是域 - api.com。 The specific url inside that domain, this is something for api gateway owners to decide on.该域内的特定 url,这是由 api 网关所有者决定的。

Typically there are two different approaches to api. In your example, there are two services and one way of exposing them to customers would be:通常有两种不同的 api 方法。在您的示例中,有两种服务,一种将它们公开给客户的方法是:

  • products.api.yourcompany.com产品.api.你的公司.com
  • users.api.yourcompany.com用户.api.yourcompany.com

Clearly, each service would own its own endpoint (domain) and they can use any url format for specific operations;显然,每个服务都将拥有自己的端点(域),并且它们可以使用任何 url 格式进行特定操作; like /operationAbc or exec?operation=abc etc.像 /operationAbc 或 exec?operation=abc 等。

The second approach, and this is were api gateways shine, both services can be hidden behind single endpoint: api.yourcompany.com - and the api gateway decides how actual operation call looks like.第二种方法,这是 api 网关的亮点,两种服务都可以隐藏在单个端点后面:api.yourcompany.com - api 网关决定实际操作调用的样子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM