Adsk.Platform.HttpClient
0.1.15
dotnet add package Adsk.Platform.HttpClient --version 0.1.15
NuGet\Install-Package Adsk.Platform.HttpClient -Version 0.1.15
<PackageReference Include="Adsk.Platform.HttpClient" Version="0.1.15" />
<PackageVersion Include="Adsk.Platform.HttpClient" Version="0.1.15" />
<PackageReference Include="Adsk.Platform.HttpClient" />
paket add Adsk.Platform.HttpClient --version 0.1.15
#r "nuget: Adsk.Platform.HttpClient, 0.1.15"
#:package Adsk.Platform.HttpClient@0.1.15
#addin nuget:?package=Adsk.Platform.HttpClient&version=0.1.15
#tool nuget:?package=Adsk.Platform.HttpClient&version=0.1.15
Adsk.Platform.HttpClient
Adsk.Platform.HttpClient
is a dependency of the APS toolkit libraries, and it's used by default to make HTTP requests to the Autodesk Platform (APS) API endpoints.
Adsk.Platform.HttpClient
is a implementation of System.Net.Http.HttpClient
.
Compare to the standard System.Net.Http.HttpClient
, this implementation has the following features:
- Retry logic
- Error handling
- Url Redirection
- [Concurrency rate limit](#Preventive rate limit)
Installation
dotnet add package Adsk.Platform.DataManagement
This package is a dependency of the other packagesAdsk.Platform.*
.
Usage
In the following example, we create a new instance of DataManagementClient
is based on the HttpClient
implementation.
using Autodesk.DataManagement;
public async Task<Hubs> GetHub()
{
async Task<string> getAccessToken()
{
//return access token with your logic
}
var DMclient = new DataManagementClient(getAccessToken);
var hubs = await DMclient.DataMgtApi.Project.V1.Hubs.GetAsync();
return hubs;
}
Preventive rate limit
The rate limit is defined by the maximum number of concurrent requests and the time window. This limit is per endpoint.
public async Task GetUsersConcurrently()
{
//Limit to 10 requests per second
var requestTimeWindow = TimeSpan.FromMilliseconds(1000);
var httpClient = Autodesk.Common.HttpClientLibrary.HttpClient.Create((10, requestTimeWindow));
//Just run all tasks in parallel. The HttpClient will handle the concurrency rate limit
var tasks = new List<Task>();
for (int i = 0; i < 20; i++)
{
var resp = httpClient.GetAsync("https://randomuser.me/api/");
tasks.Add(resp);
}
await Task.WhenAll(tasks);
}
By default, the concurrency rate limit is disabled.
Note: The concurrency rate limit is per endpoint, not global.
Error handling
The error handler throw an HttpRequestException
exception if:
- Status code is not in the range 200-299
- Status code is not handled by the retry logic or the redirection logic
The exception message contains the response status code and the endpoint response content as a string
.
using Autodesk.DataManagement;
public async Task<Hubs> GetHub()
{
async Task<string> getAccessToken()
{
//return access token with your logic
}
var DMclient = new DataManagementClient(getAccessToken);
try {
var hubs = await DMclient.DataMgtApi.Project.V1.Hubs.GetAsync();
return hubs;
} catch (HttpRequestException ex) {
Console.WriteLine(ex.StatusCode);
Console.WriteLine(ex.Message); //Response content returned by the API endpoint
}
}
Retry logic
The client uses the default retry logic provided with Kiota
. The code below shows which status codes are considered as 'retry-able'.
private static bool ShouldRetry(HttpStatusCode? statusCode)
{
return statusCode switch
{
HttpStatusCode.ServiceUnavailable => true,
HttpStatusCode.GatewayTimeout => true,
(HttpStatusCode)429 => true,
_ => false
};
}
Url Redirection
The client uses the default redirection logic provided with Kiota
. The code below shows which status codes are considered as redirection.
private static bool IsRedirect(HttpStatusCode statusCode)
{
return statusCode switch
{
HttpStatusCode.MovedPermanently => true,
HttpStatusCode.Found => true,
HttpStatusCode.SeeOther => true,
HttpStatusCode.TemporaryRedirect => true,
(HttpStatusCode)308 => true,
_ => false
};
}
Bring your own HttpClient
This default httpClient
can be replaced by your own implementation.
For example, the Polly library could be used to implement a retry policy.
using System;
using System.Net.Http;
using Microsoft.Extensions.Http;
using Microsoft.Extensions.Http.Resilience;
using Polly;
using Autodesk.DataManagement;
public async Task<Hubs> GetHub()
{
async Task<string> getAccessToken()
{
//return access token with your logic
}
// Create a custom HttpClient
var customHttpClient = CreateHttpClient();
//Pass it to the DataManagementClient
var DMclient = new DataManagementClient(getAccessToken, customHttpClient);
var hubs = await DMclient.DataMgtApi.Project.V1.Hubs.GetAsync();
return hubs;
}
// Create a custom HttpClient with a Polly retry policy
private HttpClient CreateHttpClient() {
var retryPipeline = new ResiliencePipelineBuilder<HttpResponseMessage>()
.AddRetry(new HttpRetryStrategyOptions
{
BackoffType = DelayBackoffType.Exponential,
MaxRetryAttempts = 3
})
.Build();
var socketHandler = new SocketsHttpHandler
{
PooledConnectionLifetime = TimeSpan.FromMinutes(15)
};
var resilienceHandler = new ResilienceHandler(retryPipeline)
{
InnerHandler = socketHandler,
};
return new HttpClient(resilienceHandler);
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Http (>= 9.0.7)
- Microsoft.Kiota.Http.HttpClientLibrary (>= 1.19.0)
NuGet packages (9)
Showing the top 5 NuGet packages that depend on Adsk.Platform.HttpClient:
Package | Downloads |
---|---|
Adsk.Platform.ACC.AccountAdmin
Autodesk Platform: ACC Account service SDK and tools |
|
Adsk.Platform.DataManagement
Autodesk Platform: Data Management Service SDK and tools |
|
Adsk.Platform.Authentication
Autodesk Platform: Authentication Service SDK and tools |
|
Adsk.Platform.ACC.CostManagement
Autodesk Platform: ACC Cost Service SDK and tools |
|
Adsk.Platform.ACC.ModelProperties
Autodesk Platform: ACC Model Properties Service SDK and tools |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
0.1.15 | 27 | 8/9/2025 |
0.1.14 | 91 | 7/31/2025 |
0.1.13 | 87 | 7/31/2025 |
0.1.12 | 66 | 7/18/2025 |
0.1.11 | 152 | 6/27/2025 |
0.1.10 | 142 | 6/27/2025 |
0.1.9 | 329 | 6/9/2025 |
0.1.8 | 206 | 6/4/2025 |
0.1.7 | 196 | 6/3/2025 |
0.1.6 | 256 | 4/23/2025 |
0.1.5 | 224 | 4/23/2025 |
0.1.4 | 217 | 4/3/2025 |
0.1.3 | 449 | 10/17/2024 |
0.1.2 | 163 | 10/16/2024 |
0.1.1 | 167 | 10/16/2024 |
0.1.0 | 174 | 10/16/2024 |
0.0.16 | 169 | 10/14/2024 |
0.0.15 | 168 | 10/14/2024 |
0.0.14 | 172 | 10/14/2024 |
0.0.13 | 313 | 9/18/2024 |
0.0.12 | 227 | 7/30/2024 |
0.0.11 | 182 | 7/16/2024 |
0.0.10 | 178 | 7/16/2024 |
0.0.9 | 174 | 5/31/2024 |
0.0.8 | 183 | 5/22/2024 |
0.0.7 | 147 | 5/14/2024 |
0.0.6 | 205 | 5/4/2024 |
0.0.5 | 173 | 5/3/2024 |
0.0.4 | 190 | 4/30/2024 |
0.0.3 | 195 | 4/30/2024 |