ASP.NET WebAPI URL版本控制

时间:2016-03-02 10:43:46

标签: azure iis asp.net-web-api azure-web-sites

我们希望创建通用公共Web服务,并创建自定义API。 但是如何隔离,版本化并将这些端点绑定为超大规模系统?

我们希望:

  • 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),这个线程很老,没有答案。

1 个答案:

答案 0 :(得分:1)

我总是使用该版本作为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中使用逻辑服务它会有意义:

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