在 WSO2 API 管理器中为后端服务和 API 定义定义 URL 模式和版本控制的推荐方法是什么

What's the recommended way to define URL patterns and versioning for backend services and API definitions in WSO2 API Manager

在 WSO2 API 管理器中包含我们的 Java 应用程序服务时,我们遇到了一个问题。我们典型的后端应用程序在 Tomcat 上运行并具有上下文路径,例如(/客户经理)。它的 Spring 控制器使用以下格式定义端点:/api/VERSION/resource,例如:/api/v1/customers/api/v2/customers

因此,我们对后端的调用如下所示:http://localhost:8080/customer-manager/api/v1/customer。我们自动生成的 swagger 文档将 REST 路径信息发布为 /customer-manager/api/v1/customers.

现在,当在 WSO2 中创建一个 API 定义时,我们被迫指定一个上下文路径和一个版本(/customer-manager,v1),并且此信息被添加到 API调用,所以我们的 WSO2 API 调用是这样的:

https://WSO2_HOST:WSO2_PORT/customer-manager/v1/customer-manager/api/v1/customers

如您所见,上下文路径和版本重复

所以这提出了几个问题:

后台有上下文和版本详细信息 URL 是正常的,并不总是可以从后台删除它们。通过查看问题,我假设您正在尝试使用 swagger 文件发布 API 。也许您必须检查为什么 swagger 定义将“/customer-manager/api/v1/customers”设置为 Rest 路径(资源)。如果您可以更新后端以将“/customer-manager/api/”设置为基本路径并将 "customer" 设置为资源,则可以避免重复的上下文路径。

如果是这种情况,您可以使用以下选项创建 API。

Name: customer-manager
Context: /customer-manager/api
Version: v1
Resource: customers (This will be identified through Swagger definition)
Backend URL: http://localhost:8080/customer-manager/api/v1

如果无法更改 swagger 定义,您可以通过如上所述定义资源而不是使用基于 Swagger 的选项在 API 管理器中创建 API 定义。在这种情况下,您可以使用 设计新的 REST API 选项。