【问题标题】:How to specify the API version?如何指定 API 版本?
【发布时间】:2018-11-23 23:30:18
【问题描述】:

根据Azure DevOps Services REST API Reference,请求URI的格式如下:

https://{instance}[/{team-project}]/_apis[/{area}]/{resource}?api-version={version}

关于api-version

每个 API 请求都应包含一个 api 版本,以避免您的应用或服务随着 API 的发展而中断。

我开始使用.NET client libraries for Azure DevOps Services (and TFS) 以编程方式管理仪表板。

我能够使用个人访问令牌连接到 Azure DevOps:

var credential = new VssBasicCredential(string.Empty, "PersonalAccessToken");

using (VssConnection connection = new VssConnection(new Uri("...."), credential))
using (var client = connection.GetClient<DashboardHttpClient>())
{
     // ...
}

如何指定 API 版本?使用.NET client libraries 时这样做是否仍然有意义?

【问题讨论】:

    标签: c# rest azure azure-devops azure-devops-rest-api


    【解决方案1】:

    API 版本由客户端库决定。您可以通过拆卸它们来确认这一点(例如使用 ILSpy)。

    例如,在Microsoft.TeamFoundationServer.Client 的当前稳定版本中,DashboardHttpClientBase 有一个CreateDashboardAsnc 方法,该方法进行以下调用:

    this.SendAsync<Dashboard>(..., new ApiResourceVersion("4.1-preview.2"), ...);
    

    【讨论】:

      猜你喜欢
      • 2015-03-10
      • 2022-10-31
      • 1970-01-01
      • 1970-01-01
      • 2017-11-15
      • 1970-01-01
      • 2012-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多