'Purpose of SendGrid binding in Azure Function App

I know that Azure Function Apps supports using the SendGrid binding out of the box to send emails using SendGrid. But what I can't seem to find is any information on the architecture/advantages/purposes of this as opposed to just calling the SendGrid API directly.

So at the moment I have a python function app and a function for an HTTP request/response (i.e. 2 output bindings, the HTTP Response and the SendGrid output binding). Is there any disadvantage if instead I'd rather just call the SendGrid API directly through python HTTP requests and not by setting the output binding?

I cannot figure out what is happening under the hood - does Azure wait to make the Sendgrid request (from the output binding) before making the HTTP response? That doesn't seem to be the case, as the HTTP request errors if something goes wrong on the sendgrid part. So is there any time/network advantage to using the output binding?

Or is it that the output binding exists simply to provide a language-independent "client" (JSON-string) to sendgrid emails and the main client to sendgrid can be maintained in a C# extension?

I almost feel like it is advantageous to make the calls directly to Sendgrid. If I am attempting to send an email earlier on in my function, and that function is written as async, then it could return as soon as the rest of it is done (if sendgrid has already returned). I just want to make sure I am not missing something and not taking advantage of something the output binding offers.



Solution 1:[1]

Output bindings of any sort are just for convenience mostly as they will handle the clients and connections established without you having to set up code yourself for this. They are optimized too, with the backend architecture in mind to ensure connections are re-used and handled properly so you may not reach any issues with SNAT port exhaustion or Connection limits on the machine itself. They are mostly a convenience, but they are all open source as well on github. You can take the time to look through them if you like if you want a better understanding of how they work:
-https://github.com/Azure/azure-webjobs-sdk-extensions/blob/dev/src/WebJobs.Extensions.SendGrid/SendGridAttribute.cs

If you need any special considerations or configurations that the binding doesn't have, then I would say go ahead and use your code. Just remember to take connection handling for functions into consideration such as re-using connections and establishing a singleton or static global variable for your http client.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tspring