在 API Gateway 上部署 Cloud Endpoints API
Cloud Endpoints 是一个 API 管理系统,可帮助您保护、监控、分析和设置 API 配额。Endpoints 使用 Extensible Service Proxy (ESP) 或 Extensible Service Proxy V2 (ESPv2) 托管您的 API。
使用 Endpoints 时,您可以通过以下三种方式定义 API:
- 适用于 OpenAPI 的 Cloud Endpoints
- 适用于 gRPC 的 Cloud Endpoints
- 适用于 App Engine 标准环境的 Cloud Endpoints Frameworks
使用 API Gateway 开发 API
Endpoints 和 API Gateway 都支持使用 OpenAPI 规范(OpenAPI 2.0 或 OpenAPI 3.x)描述的 API。如果您已使用 OpenAPI 定义 Endpoints API,这意味着您也可以在 API Gateway 上部署 Endpoints API。
在 API Gateway 上部署 Endpoints OpenAPI 规范
API Gateway 支持的 OpenAPI 规范定义格式和选项与适用于 OpenAPI 的 Cloud Endpoints 支持的相同。 这意味着您可以使用 Endpoints OpenAPI 规范中的安全性、配额和其他定义来定义 API Gateway 中的 API。
Endpoints 和 API Gateway 之间的唯一区别是它们如何处理 OpenAPI 规范定义中的 host 属性:
- 在 Endpoints 中,将
host属性设置为部署 ESP 或 ESPv2 时创建的网址的主机名部分,其中 ESP 或 ESPv2 是用于托管 Endpoints API 的服务。 - 在 API Gateway 中,省略
host或将其设置为已部署 API 的 DNS 名称。与 API 使用方共享 OpenAPI 规范时,API 提供商通常会将其设置为 DNS 名称。但是,API Gateway 不会强制执行host属性的值。
例如,下面是 OpenAPI 定义的一部分,Endpoints 使用它来定义 API 以访问在 Cloud Run functions 上部署的后端服务:
OpenAPI 2.0
swagger: '2.0' info: title: Cloud Endpoints + GCF description: Sample API on Cloud Endpoints with a Google Cloud Functions backend version: 1.0.0 host: HOST schemes: - https ...
OpenAPI 3.x
openapi: 3.0.4 info: title: Cloud Endpoints + GCF description: Sample API on Cloud Endpoints with a Google Cloud Functions backend version: 1.0.0 servers: - url: https://HOST x-google-endpoint: {} ...
如需详细了解如何为 API 定义创建 OpenAPI 规范,请参阅 OpenAPI 概览。