Replace RestSharp with HttpClient to eliminate dependency conflicts#16841
Replace RestSharp with HttpClient to eliminate dependency conflicts#16841
Conversation
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>
| 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); |
|
@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>
Fixed in commit 27758e7. Removed |
|
@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 |
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 viaHttpClient.Timeout)NodeAutoCompleteBarViewModel.cs- Generic autocomplete API calls with Bearer token authDynamoMLDataPipeline.cs- Data pipeline POST/PUT operations with Bearer token authDynamoPackagesAnalyzer/DynamoPackagesSource.cs- Package download GET requests with async/awaitProject references:
API changes:
IOAuth2AuthProviderinterface implementation fromIDSDKManager(interface required RestSharp types)IDSDKManager.SignRequest()andIDSDKManager.LoginRequest()methods (unused and required RestSharp types)GetAccessToken()fromIOAuth2AccessTokenProviderremains as the API for obtaining bearer tokensExample
Before:
After:
JSON serialization continues using Newtonsoft.Json for consistency.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.