smsapi / smsapi-csharp-client

SMSAPI C# client that allows you to send messages and administrate your SMSAPI account.
https://www.smsapi.com/
29 stars 20 forks source link

Use IHttpClientFactory #41

Open Misiu opened 5 months ago

Misiu commented 5 months ago

I plan to use SMSAPI inside a rest API. The preferred way of using HttpClient is by using https://learn.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-8.0.

Maybe a sample of how to register the client (of the factory) inside DI should be added?

Any info on when the next version of the library will be released?

mpawikowski commented 5 months ago

Hello,

I forwarded your questions to our IT department.

jakublabno commented 5 months ago

Hello, in version 3 we got rid of RestSharp in favour of HttpClient https://github.com/smsapi/smsapi-csharp-client/tree/3.x.x-dev HttpClient is being created on the fly in ProxyHTTP, so there is no need to be managed by asp core.

Unfortunatelly, there is no common interface for http actions in .net, so what you can do is to make your own implementation of SMSApi.Api.Proxy or decorate it and use it as following

var client = new ClientOAuth("token");
var proxy = YourProxyInstance, you get get it e.g. from your container
var features = new Features(client, proxy);

However, we will discuss about possibillity of passing own HttpClient to proxy.

We are planning to to release 3.x version in a few months, however, if you want, you can build it for you own or contact us to do it so, but pleaes note that it is not fully tested version yet.

The recommended way in asp.net is to keep registered SMSApi.Api.Features service as transient in your service collection

Misiu commented 5 months ago

@jakublabno, thank you for the reply and provided feedback. Passing HttpClient might help or maybe a custom factory that we could use to return/create httpclient when needed. I need to use your library in a background service to send messages that are send from multiple microservices, so not sure if transient is a good scope. I'll take a look at 3.x.x branch and will try to use it in my project.

Looking forward to the release!

jakublabno commented 5 months ago

@Misiu for now, I've pushed a change https://github.com/smsapi/smsapi-csharp-client/commit/eda66cbaed0b3f2c8c734cd00afc994d3967098d Please let me know if it is sufficient for now, also PRs are welcome if you have some good ideas :)

anddrzejb commented 1 month ago

Is there any roadmap to release 3.x.x? RestSharp is popping up in OWASP vulnerabilities tool.

jakublabno commented 1 month ago

We had to postpone the release of the new version; however, work has resumed this week. We may also release a pre-release version earlier than stable one. We'll be ready to release 3.0.0 after our QA teams done testing.