Api Maintains state when reusing endpoint
granthoff1107 opened this issue · comments
The Api Endpoint maintain the old URL Segments from past requests:
var apiConfig = new ApiKeyConfig();
apiConfig.ApiKey = apiKey;
apiConfig.ApiSecret = apiSecret;
var coinbaseApi = new CoinbaseApi(apiConfig);
var apiAccounts = await coinbaseApi.Accounts.ListAccountsAsync();
var apiAccount = apiAccounts.Data.FirstOrDefault(x => x.Name == "ETH Wallet");
var apiAddresses = await coinbaseApi.Addresses.ListAddressesAsync(apiAccount.Id);
var apiAddress = apiAddresses.Data.FirstOrDefault();
var transactions = await coinbaseApi.Transactions.ListTransactionsAsync(apiAccount.Id);
In this senario transactions will 404 because Transactions internally uses the Accounts api,
return this.AccountsEndpoint
.AppendPathSegments(accountId, "transactions")
.WithClient(this)
.GetJsonAsync<PagedResponse<Transaction>>(cancellationToken);
AppendPathSegments will cause the internal endpoints to maintains the state, so the previous requests will have the old path segments. This seems like a larger architecture change but it probably could be solved by changing the Endpoint types from Url to Func
and then just initializing like so:
this.AccountsEndpoint = () => this.config.ApiUrl.AppendPathSegment("accounts");
this.PaymentMethodsEndpoint = () => this.config.ApiUrl.AppendPathSegment("payment-methods");
//...
Hi Grant,
My apologies. It was a total misunderstanding on my part. I thought each call to AppendPathSegment
created a new URL object.
But apparently, it creates a new URL
object only from string
and subsequent calls mutate the URL
object if it already exists.
This should be fixed in v5.0.0-beta-4
.
https://www.nuget.org/packages/Coinbase/5.0.0-beta-4
Thanks again for testing! Sorry for the frustration. 😿 Hopefully I got it right this time. :)
Thanks,
Brian