How to specify the API version?

て烟熏妆下的殇ゞ 提交于 2019-12-11 07:49:19

问题


According to the Azure DevOps Services REST API Reference, the request URI has the following format:

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

Regarding the api-version:

Every API request should include an api-version to avoid having your app or service break as APIs evolve.

I started using the .NET client libraries for Azure DevOps Services (and TFS) to manage dashboards programmatically.

I am able to connect to Azure DevOps using a Personal Access Token:

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

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

How can I specify the API version? Does it still make sense to do it, when using the .NET client libraries?


回答1:


The API version is decided by the client libraries. You can confirm this by disassembling them (e.g. using ILSpy).

For example, in the current stable release of Microsoft.TeamFoundationServer.Client, DashboardHttpClientBase has a CreateDashboardAsnc method that makes the following call:

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


来源:https://stackoverflow.com/questions/53448377/how-to-specify-the-api-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!