Last active
July 8, 2017 04:50
-
-
Save louh/45792fa5b6844506c5097e50d615c37b to your computer and use it in GitHub Desktop.
SendGrid's new client library is way worse.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sendgrid = require('sendgrid')(process.env.SENDGRID_USERNAME, process.env.SENDGRID_PASSWORD) | |
sendgrid.send({ | |
to: '[email protected]', | |
from: '[email protected]', | |
subject: 'Hello World from the SendGrid Node.js Library', | |
text: 'some text here' | |
}, function (err, json) { | |
if (err) { | |
res.status(500).json({ msg: 'Could not send feedback.' }) | |
return | |
} | |
res.status(202).json({ msg: 'Feedback accepted.' }) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var helper = require('sendgrid').mail | |
from_email = new helper.Email("[email protected]") | |
to_email = new helper.Email("[email protected]") | |
subject = "Hello World from the SendGrid Node.js Library" | |
content = new helper.Content("text/plain", "some text here") | |
mail = new helper.Mail(from_email, subject, to_email, content) | |
var sg = require('sendgrid').SendGrid(process.env.SENDGRID_API_KEY) | |
var requestBody = mail.toJSON() | |
var request = sg.emptyRequest() | |
request.method = 'POST' | |
request.path = '/v3/mail/send' | |
request.body = requestBody | |
sg.send(request, function (response) { | |
console.log(response.statusCode) | |
console.log(response.body) | |
console.log(response.headers) | |
}) |
Just upgraded to the new Sendgrid node library and have to agree - it's Java-hell.
I literally googled "sendgrid api way worse"
And I get this gist subtitled "SendGrid's new client library is way worse." hahaha
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The only thing better in the v3 client library is using API keys instead of a username / password. Everything else just looks uglier.
What the hell is an
emptyRequest()
? Why would we ever need to call it on our own, rather than have it be abstracted away by the library itself?