-
Notifications
You must be signed in to change notification settings - Fork 43
What is the benefit of this client? #15
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
Comments
Part of the question/answer is here: sendgrid/sendgrid-csharp#261 (comment) These are valid points as well as in the other thread. I'll leave this ticket open so that others may weigh in. Some of the reasons we decided to create our own client in a separate repo:
|
Hey Elmer, Thanks for your response. Here's my 2 cents:
|
Thanks again for contributing more great feedback! Please keep it coming. Regarding 1, we need to also account for the other verbs, so we are using I'd love to simply have client.send(mail), which I think we will achieve with the helper once we get to iterating on that again. The user should not have to worry about what the actual path to the endpoint is, though I think they should have that option for flexibility, especially since it will be some time before we have helpers for all the major use cases. Fully agreed on point 2. And for C#, you are playing a big part in helping us get that right for this language. So thanks again! I'm not sure I follow point 3. I think you mean in regards to the simplicity. If so, agreed, there is work to be done there, but we have only just begun :) Regarding 4, I'm not sure yet either. We need to dig a bit deeper and hopefully others in this community will chime in. In any case, before we make our next iteration on this component of the library, we will create an issue and solicit further feedback and your feedback will be incorporated. Perhaps you may want to submit an issue that proposes to remove the dependency from the SendGrid and just use HTTPClient within the library. That might hopefully spark some additional feedback. |
I'm not saying there's no benefit for a client of your own the user can use without caring about the underlying REST calls, that's actually pretty cool. I'm just saying that IMO dynamic isn't the way to go here. I was thinking more about the lines of "contain and delegate" using an underlying HttpClient, with an optional user-supplied public sealed class SendGridClient
{
HttpClient m_client;
public SendGridClient(
string apiKey, string baseAddress = null, HttpMessageHandler handler = null)
{
m_client = new HttpClient(handler ?? new HttpClientHandler())
{
DefaultRequestHeaders =
{
Authorization = new AuthenticationHeaderValue("Bearer", apiKey)
},
BaseAddress = new Uri(baseAddress ?? "https://api.sendgrid.com/v3/")
};
}
// As the next phase you could wrap HttpResponseMessage in a class of your own too
public Task<HttpResponseMessage> SendMailAsync(Mail mail)
{
return m_client.PostAsync(
"mail/send", new StringContent(mail.Get(), Encoding.UTF8, "application/json"));
}
//... implement more SendGrid-specific methods ...
} As for the missing methods, in my opinion you should let the users fend for themselves with the REST API until the official client support arrives - it's really quite simple. Anything else would feel half-baked, like a "mix" of official and custom methods. If you still want them to use your client I see two options:
|
BTW like I mentioned in the other thread you could also enrich the helper classes for example: class Mail
{
//...
Task<HttpResponseMessage> SendAsync(string apiKey)
{
return new SendGridClient(apiKey).SendMailAsync(this);
}
} You can also do this with extension methods if you don't want the helper classes to be aware of the client. |
Hi @ohadschn, I'm not sure if you saw the new v9 of our SDK, but just wanted to point you there as I close this issue. Our SDK is no longer dependent on this library (and is now no longer using dynamics) and we will leave the dynamic functionality here in this SDK. Thanks! |
@thinkingserious that's great news, thanks! |
Uh oh!
There was an error while loading. Please reload this page.
I apologize for the blunt question, but why not just use
HttpClient
?What's the difference between
sgClient.your.api.get()
andhttpClient.GetAsync("Your/API")
?The former might be confusing to C# developers, as the API calls are not truly type safe and are pretty much equivalent to the string...
The text was updated successfully, but these errors were encountered: