A Microservice to send out emails using SendGrid
Create a file .env
with appropriate ENV. VARIABLES Values. Application reads this value while bootstrapping. e.g. Fill the SandGrid API Key and Template Id.
SENDGRID_API_KEY=""
FROM_EMAIL="vs4vijay@gmail.com"
TEMPLATE_SALE_SUMMARY="d-8ee94062b404488094ee4d1b44fb3d0c"
APP_URL="https://www.huddl.ai/features"
SENDER_NAME="Vijay Soni"
- Template is provided in
/templates
folder, Please upload it on SandGrid and get the template id
npm install
ORyarn
node src/app.js
ORnpm start
ORnpm start | pino-pretty
docker build -t email-service .
docker run -p 3333:3333 --env-file=".env" email-service
docker build -t vs4vijay/email-service .
docker login
docker push vs4vijay/email-service
Request: POST /api/v1/email
Body:
{
"email": "vs4vijay@gmail.com",
"metadata": {
"name": "Vijay Soni",
"sale_id": "BigBillionDay101"
}
}
Example:
curl -X POST -d '{"email":"vs4vijay@gmail.com","metadata": {"name":"Jay Kumar","sale_id":123}}' "http://0.0.0.0:3333/api/v1/email" -H "Content-Type: application/json"
- Basic Node + Express
- Dockerize
- Run as non-root user
- Multistage Build
- Kubernetes (Good to have)
- Deploy to Cloud
- nginx
- Code
- Use
yarn
instead ofnpm
- Validation and Error Frameworks
- Enhance the code structure and decouple
- Use
npm i -D prettier eslint eslint eslint-config-prettier eslint-plugin-prettier
Install ESLint
Install Prettier
printWidth: 80
curl -X POST -d '{"metadata": {}}' "0.0.0.0:3333/api/v1/email" -v -H "Content-Type: application/json"
curl -X POST -d '{"email":"vs4vijay@gmail.com","metadata": {"name":"Jay Kumar","sale_id":888}}' "0.0.0.0:3333/api/v1/email" -H "Content-Type: application/json"
class based controller