Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could we have .WithBaseUrl() option? #495

Closed
AndrewZenith opened this issue Dec 9, 2024 · 6 comments
Closed

Could we have .WithBaseUrl() option? #495

AndrewZenith opened this issue Dec 9, 2024 · 6 comments
Labels
status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question

Comments

@AndrewZenith
Copy link

Hi,

I have a number of services that I use which share the same interface but use different base addresses. For instance a Live and Test service. There are reasons for the system to communicate with both systems rather than just one or the other.

Unless I am missing something we either have to set the baseurl at the time of the client creation, or override the entire Url in the call using .WithUrl()

It would seem to be so much simpler to have a .WithBaseUrl() option to just override the base address for this, and looking at the code it seems like it would be simple enough to implement.

At present the options for this appear to be:

  1. 'destroy' and re-create the apiclient after each call
  2. create multiple ApiClients in a dictionary to get the correct one for the call
  3. Override the full Url for each call (many endpoints though - annoying to keep track).

These all seem suboptimal compared to having a .WithBaseUrl() option.

Thoughts?

@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Dec 9, 2024
@baywet
Copy link
Member

baywet commented Dec 9, 2024

Hi @AndrewZenith
Thank you for using kiota and for reaching out.

Have you tried setting the base url of the request adapter of your client

Let us know if you have any additional comments or questions.

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question labels Dec 9, 2024
@baywet baywet moved this from Needs Triage 🔍 to Waits for author 🔁 in Kiota Dec 9, 2024
@AndrewZenith
Copy link
Author

Hi,

That's what I'm already doing. As I mentioned, you can't change it once the ApiClient is created, leading to the question of having a .WithBaseUrl() option.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Dec 9, 2024
@baywet
Copy link
Member

baywet commented Dec 9, 2024

Thank you for the additional information.

Have you considered having multiple request adapters and clients? and switching between them instead? If so, what are the challenges it posses?

Generally speaking, the request adapter holds all the configuration for the client. (auth, serialization, base url, etc...)

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels Dec 9, 2024
@AndrewZenith
Copy link
Author

Hi,

At present I am using my option (2) - create multiple ApiClients in a dictionary to get the correct one for the call

I was rather hoping to just be able to have a single ApiClient rather than multiple, everything else other than the BaseUrl seems configurable via the RequestOptions.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Dec 9, 2024
@baywet
Copy link
Member

baywet commented Dec 9, 2024

You could achieve that via a custom middleware handler and the associated option.

But I question whether this is desirable: you'll effectively end up mixing the environment switching logic with the application logic.

Instead this could/should be handled by the configuration layer/through dependency injection.

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels Dec 9, 2024
@AndrewZenith
Copy link
Author

Hi,

I'm building the clients through a factory as I could potentially need to add a new endpoint address and I want to do that dynamically whilst the application is running if needed.
If I didn't do that then I can see I should have all the services in startup to support each client, which would mean having multiple clients anyway.
So, I'm using a dictionary of clients in my single service - and yes, that way I don't have to change the BaseUrl for each usage of the client.
So I'm good with what I have.

@github-project-automation github-project-automation bot moved this from Waits for author 🔁 to Done ✔️ in Kiota Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question
Projects
Status: Done ✔️
Development

No branches or pull requests

2 participants