wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
335 stars 131 forks source link

The need for setting a HttpClient base address #312

Closed PetesBreenCoding closed 3 months ago

PetesBreenCoding commented 2 years ago

Hi , should it really be necessary to set a BaseAddress if passing a HttpClient instance to the constructor? If I want to re-use a HttpClient instance in multiple places (including for non-WordPress uses) then setting a BaseAddress limits that. Would it not be better to take the HttpClient and base URL separately?

PetesBreenCoding commented 2 years ago

Looking at the code, I can do this, but not ideal:

var originalBaseAddress = httpClient.BaseAddress; 
httpClient.BaseAddress = new Uri("...");
var wpClient = new WordPressClient(httpClient);
httpClient.BaseAddress = originalBaseAddress;
ThomasPe commented 2 years ago

I'm not against making this more flexible. Can't promise if I can get to it soon, but happy to look at a PR.

ThomasPe commented 3 months ago

done