<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nuno Faria</title>
    <description>The latest articles on DEV Community by Nuno Faria (@nunofaria11).</description>
    <link>https://dev.to/nunofaria11</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F10718%2F2145649.jpeg</url>
      <title>DEV Community: Nuno Faria</title>
      <link>https://dev.to/nunofaria11</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nunofaria11"/>
    <language>en</language>
    <item>
      <title>Sendgrid API + NodeJS project template</title>
      <dc:creator>Nuno Faria</dc:creator>
      <pubDate>Mon, 04 Jan 2021 23:56:36 +0000</pubDate>
      <link>https://dev.to/nunofaria11/sendgrid-api-nodejs-project-template-15me</link>
      <guid>https://dev.to/nunofaria11/sendgrid-api-nodejs-project-template-15me</guid>
      <description>&lt;p&gt;Projects quickly reach a point where it is necessary to send emails, maybe a contact form or a password reset feature.&lt;/p&gt;

&lt;p&gt;It is possible to use the &lt;a href="https://sendgrid.com/docs/API_Reference/api_v3.html"&gt;Sendgrid Mail API v3&lt;/a&gt; directly on a website but it is entirely not recommended since it means exposing the Sengrid API key.&lt;/p&gt;

&lt;h2&gt;
  
  
  A project template
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://github.com/nunofaria11/sendgrid-nodejs-endpoint"&gt;sendgrid-nodejs-endpoint&lt;/a&gt; project is meant to be used as a template - it provides the following features out-of-the-box:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;configurable allowed origins&lt;/li&gt;
&lt;li&gt;configurable allowed recipients&lt;/li&gt;
&lt;li&gt;Basic or Digest authentication&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Configured by specifying environment variables when deployed (or a &lt;code&gt;.env&lt;/code&gt; file) and a passfile with authentication data if necessary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PORT=3001
SENDGRID_API_KEY=&amp;lt;Sendgrid API key&amp;gt;

FROM=sender@mail.com
ALLOWED_RECIPIENTS=recipient1@mail.com recipient2@mail.com

ALLOWED_ORIGINS=http://example.com

AUTH_SCHEME=Digest
AUTH_REALM=test-realm
AUTH_PASSFILE=/path/users.passfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  REST Endpoints
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;"/" root endpoint&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;GET endpoint responds with "Hello World!" message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; GET /
&amp;lt; 200 OK
{
  "message": "Hello World!"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;"/mail" endpoint&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;POST endpoint receives body with JSON object and uses the same object API as &lt;a href="https://github.com/sendgrid/sendgrid-nodejs/tree/main/packages/mail"&gt;Sendgrid NodeJS API&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; POST /mail
{
    "to": "recipient@mail.com",
    "subject": "test sendgrid client",
    "text": "test sendgrid client",
    "html": "test sendgrid client"
}

&amp;lt; 200 OK
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>sendgrid</category>
      <category>email</category>
      <category>node</category>
    </item>
  </channel>
</rss>
