我们希望创建通用公共(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/