Skip to content

Replace RestSharp with HttpClient to eliminate dependency conflicts#16841

Draft
Copilot wants to merge 5 commits intomasterfrom
copilot/migrate-from-restsharp-to-httpclient
Draft

Replace RestSharp with HttpClient to eliminate dependency conflicts#16841
Copilot wants to merge 5 commits intomasterfrom
copilot/migrate-from-restsharp-to-httpclient

Conversation

Copy link
Contributor

Copilot AI commented Jan 20, 2026

RestSharp dependency causes version conflicts between Dynamo, Revit hosts, and package authors. Migrated to built-in .NET HttpClient.

Changes

HTTP client replacements:

  • NodeAutoCompleteSearchViewModel.cs - ML autocomplete API calls (7s timeout via HttpClient.Timeout)
  • NodeAutoCompleteBarViewModel.cs - Generic autocomplete API calls with Bearer token auth
  • DynamoMLDataPipeline.cs - Data pipeline POST/PUT operations with Bearer token auth
  • DynamoPackagesAnalyzer/DynamoPackagesSource.cs - Package download GET requests with async/await

Project references:

  • Removed RestSharp package from 7 .csproj files (DynamoCore, DynamoCoreWpf, DynamoMLDataPipeline, DynamoPackages, PackageDetailsViewExtension, NodeDocumentationMarkdownGenerator, DynamoPackagesAnalyzer)

API changes:

  • Removed IOAuth2AuthProvider interface implementation from IDSDKManager (interface required RestSharp types)
  • Removed IDSDKManager.SignRequest() and IDSDKManager.LoginRequest() methods (unused and required RestSharp types)
  • GetAccessToken() from IOAuth2AccessTokenProvider remains as the API for obtaining bearer tokens

Example

Before:

var options = new RestClientOptions(uri) { Timeout = new TimeSpan(0, 0, 7) };
var client = new RestClient(options);
var request = new RestRequest(string.Empty, Method.Post);
request.AddHeader("Authorization", $"Bearer {token}");
request.AddJsonBody(requestJSON);
var response = client.Execute(request);

After:

using (var client = new HttpClient())
{
    client.BaseAddress = new Uri(uri);
    client.Timeout = TimeSpan.FromSeconds(7);
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
    var content = new StringContent(requestJSON, Encoding.UTF8, "application/json");
    var response = await client.PostAsync(string.Empty, content);
}

JSON serialization continues using Newtonsoft.Json for consistency.

Original prompt

This section details on the original issue you should resolve

<issue_title>How to avoid dependency conflicts of RestSharp version between Dynamo and packages or hosts</issue_title>
<issue_description>### What did you expect to see?

There is no longer RestSharp dependency in Dynamo code base.

Details

Dynamo itself is depending on RestSharp for any RestAPI calls. This requires Dynamo aligning such version with Revit and package authors all the time.

Suggested solution:
Dynamo migrates from RestSharp to HttpClient (Built-in .NET) given HttpClient is the most common built-in replacement for RestSharp.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits January 20, 2026 17:12
Co-authored-by: QilongTang <3942418+QilongTang@users.noreply.github.com>
Co-authored-by: QilongTang <3942418+QilongTang@users.noreply.github.com>
Co-authored-by: QilongTang <3942418+QilongTang@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate from RestSharp to HttpClient in Dynamo Replace RestSharp with HttpClient to eliminate dependency conflicts Jan 20, 2026
Copilot AI requested a review from QilongTang January 20, 2026 17:23
client.Timeout = TimeSpan.FromSeconds(7);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tkn);

var content = new StringContent(requestJSON, Encoding.UTF8, "application/json");
{
var fulfillmentUrl = $"/v1/collections/{collectionId}/exchanges/{exchangeContainerId}/fulfillments:start";
RestRequest startFulfillmentRequest = new RestRequest(fulfillmentUrl);
var startFulfillmentRequest = new HttpRequestMessage(HttpMethod.Post, fulfillmentUrl);
{
var endFulfillmentUrl = $"/v1/collections/{collectionId}/exchanges/{exchangeContainerId}/fulfillments/{fulfillmentId}:finish";
RestRequest endFulfillmentRequest = new RestRequest(endFulfillmentUrl);
var endFulfillmentRequest = new HttpRequestMessage(HttpMethod.Post, endFulfillmentUrl);
var createExchangeURL = $"/v1/collections/{CollectionId}/exchanges";
RestRequest createExchangeRequest = new RestRequest(createExchangeURL);
createExchangeRequest.AddStringBody(exchangeBody, ContentType.Json);
var createExchangeRequest = new HttpRequestMessage(HttpMethod.Post, createExchangeURL);

RestRequest createBinaryRequest = new RestRequest(createBinaryAssetUrl);
createBinaryRequest.AddStringBody(createBinaryBody, ContentType.Json);
var createBinaryRequest = new HttpRequestMessage(HttpMethod.Post, createBinaryAssetUrl);
var base64CompressedBuffer = ConvertDynToBase64(filePath);
using (var fileUploadClient = new HttpClient())
{
var uploadBinaryRequest = new HttpRequestMessage(HttpMethod.Put, binaryUploadUrl);

RestRequest finishBinaryUploadRequest = new RestRequest(finishBinaryUploadUrl);
finishBinaryUploadRequest.AddStringBody(finishBinaryUploadBody, ContentType.Json);
var finishBinaryUploadRequest = new HttpRequestMessage(HttpMethod.Post, finishBinaryUploadUrl);

RestRequest syncAssetRequest = new RestRequest(syncAssetUrl);
syncAssetRequest.AddStringBody(syncAssetRequestBody, ContentType.Json);
var syncAssetRequest = new HttpRequestMessage(HttpMethod.Post, syncAssetUrl);
@QilongTang
Copy link
Contributor

@copilot Fix build error IDSDKManager.cs(14,33): error CS0535: 'IDSDKManager' does not implement interface member 'IOAuth2AuthProvider.SignRequest(ref RestRequest, RestClient)'

…stSharp migration

Co-authored-by: QilongTang <3942418+QilongTang@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 20, 2026

@copilot Fix build error IDSDKManager.cs(14,33): error CS0535: 'IDSDKManager' does not implement interface member 'IOAuth2AuthProvider.SignRequest(ref RestRequest, RestClient)'

Fixed in commit 27758e7. Removed IOAuth2AuthProvider interface implementation from IDSDKManager since it required RestSharp types (RestRequest, RestClient). The interface was only checked but never used - code now uses IOAuth2AccessTokenProvider.GetAccessToken() directly. Also completed migration of NodeAutoCompleteBarViewModel.cs to HttpClient.

client.BaseAddress = new Uri(uri);
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", tkn);

var content = new StringContent(jsonRequest, System.Text.Encoding.UTF8, "application/json");
@QilongTang
Copy link
Contributor

@zeusongit suggested to include Greg in this conversation. I believe the current PR is hitting that point. It does seem that same migration but in Greg would make more sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to avoid dependency conflicts of RestSharp version between Dynamo and packages or hosts

2 participants