jeudi 11 novembre 2021

.Net web application with different api clients

I have a Blazor project & i need to consume several REST APIs. All of those APIs require different configuration. For example: For one of those apis i have to bypass certificate by using ServicePointManager.ServerCertificateValidationCallback. And for another api i have to send GET request with bodypayload (which is not semantic). For another api i need JWT... and so forth. The point is that i have different HttpClinet(s) and they require different configuration.

So the question is how do you deal with it? You have all these amazing things in .NET like dependency injection, singleton, transient, IHttpClientFactory and you can configure your api client in startup.cs or in ctor or in any other place for that matter. So what is the right approach here?

I have a strong filling that something like strategy design pattern can be useful in this case

Aucun commentaire:

Enregistrer un commentaire