azure - ASP.NET WebAPI URL 版本控制

标签 azure iis asp.net-web-api azure-web-app-service

我们希望创建通用公共(public) Web 服务,并创建定制的 API。 但如何将这些端点隔离、版本控制和绑定(bind)为超大规模系统呢?

我们希望拥有:

  • https://api.domain.tld/v1/..
  • https://api.domain.tld/v2/..
  • https://api.domain.tld/latest/..
  • https://api.domain.tld/bosch/v1/..

  • https://domain.tld/api/v1/..
  • https://domain.tld/api/v2/..

所有端点都应隔离。在像 https://domain.tld/api/v2/.. 这样的端点后面,至少存在 3 个 ASP.NET WebAPI 实例。我们不想在 WebAPI 项目内通过命名空间来分隔版本控制,并使用内部路由配置来解决此问题。

我们希望在本地和 Azure 上都实现这种行为。 有没有任何建议或最佳实践和配置示例?

我在这里只能找到一个线程( How to version and configure WebApi with multiple aliases ),该线程非常旧并且没有答案。

最佳答案

我总是使用版本作为 api 路由,就像你一样:

https://domain.tld/api/v1/..
https://domain.tld/api/v2/..

它一直工作得很好,但其他使用 url 参数,我发现这不太明确:

Visual Studio Team Services - API

我只是不建议您采用这种模式:

https://api.domain.tld/latest/..
https://api.domain.tld/bosch/v1/..

这会让你的 API 看起来有点困惑,但如果你在 API 中使用逻辑服务,这可能是有意义的:

https://api.domain.tld/service1/v1
https://api.domain.tld/service1/v2
https://api.domain.tld/service2/v1

关于azure - ASP.NET WebAPI URL 版本控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35744900/

相关文章:

azure - Application Insights 查询显示请求总数、通过总数和失败总数

azure - 通过 REST API 获取 Azure 应用服务计划的错误 CPU 使用数据

sql-server - 失去与 Microsoft Azure SQL 数据库的连接

c# - 上传到 Azure 文件存储因大文件而失败

c# comet server 卡住 IIS

iis - Moodle IIS崩溃

c# - 找到多个与 Controller 匹配的类型

asp.net - 是否有与 Tomcat 等效的 IIS?

wcf - 何时使用MVC4 Web-API和传统的HTTP Web服务?

iis-7.5 - ASP.NET Web API 仅在某些服务器上为 PUT 返回 404