Giter Site home page Giter Site logo

siteminder-backend-assessment's Introduction

Documentation

Table of Contents


Overview

This service is created to send an email using RESTful API via Mailgun and Sendgrid.

This application provides abstraction between Mailgun and Sendgrid hence if one of the service goes down, the service can quickly failover to the other provider without affecting customers.

alt Demo


Technical Overview

Backend Technical Stack

Here are lists of my choices for this project as follows:


Getting Started

Prerequisites

  • You have to set up your account for SendGrid and Mailgun.
  • You need a valid email for the from email each providers.
  • You have to create your own .env file. (The example below)
NODE_ENV=development
PORT=8080

# Sendgrid
SENDGRID_BASE_URL=https://api.sendgrid.com/v3/
SENDGRID_API_KEY=YOUR_SENDGRID_API_KEY
[email protected]

# Mailgun
MAILGUN_BASE_URL=https://api.mailgun.net/v3/YOUR_DOMAIN/
MAILGUN_API_KEY=YOUR_MAILGUN_API_KEY
[email protected]

Installation and Run

  • Standalone
git clone https://github.com/xyzcocktail/siteminder-backend-assessment.git 
cd siteminder-backend-assessment/server
yarn (or npm install)
yarn dev (or npm run dev)
  • with Docker
git clone https://github.com/xyzcocktail/siteminder-backend-assessment.git 
cd siteminder-backend-assessment
docker-compose up -d (RUN) 
docker-compose down (STOP)
// Unit testing 
yarn test

alt Unit testing


API Document

  • Request Head
property value type required
Content-Type application/json string required

1. Send email

Request

  • [POST] /api/mail/send

Body

  • to: email (required)
  • cc: eamil (optional)
  • bcc: eamil (optional)
  • subject: string (required)
  • content: string (required)

Response example

200

{
  "message": "Email has been sent successfully!"
}

Testing with CURL

curl --request POST \
--url localhost:8080/api/mail/send \
--header 'Content-Type: application/json' \
--data '{"to": "[email protected], [email protected]", "cc": "[email protected]", "subject": "Testing from CURL", "content": "TEST Content"}'

Business Requirements

  • Create a RESTful API using Mailgun and Sendgrid.

  • Should cater for multiple email recipients with To as a mandatory and Cc and Bcc are as an option.

  • Should provide an abstraction and failover between two providers.

  • No authentication is required.

  • No 3rd party client library should be used to integrate with two providers.


Todos

  • If there was more time allowed, I could have added one more unit test for mailer function.

  • Having a proper pipelines for CI/CD will deploy automated process for more convenience.
    I usually use Jenkins as a CI/CD tool, however, I also want to try out 3rd party services such as CircleCI, TeamCity and TravisCI in the future.

  • It would be better if another version of this service is build using background processing queue such as redis, sqs, rabbitmq and kafka. because it is more efficient for scalable processing data.


Conclusion

  • I have chosen Express as a framework with Typescript and Jest as Technical Stack because:

    • I am familiar with them.
    • If we encounter some issues or problems, it is easy to solve as they are very popular libraries with easy to access the solutions.
  • I have used the class-validator library as a validator.

    By doing that, a schema of request data sent by users can be used generically as middleware.

    On top of that, customization becomes more flexible.

  • I tried to keep the code simple, easy to understand and maintainable by following OOP style coding.

  • I found a common pattern between Mailgun and Sendgrid providers which are necessary properties and then created an abstract class, BaseProvider, based on them.

    Also I have created an interface class, IProvider, which are necessary to create a provider class.

  • I created two providers MailgunProvider and SendgridProvier which inherits the BaseProvider and IProvider classes.

    Therefore, Mailer class can set those providers and send email via failOverSendmail method.

siteminder-backend-assessment's People

Contributors

jay74jung avatar

Watchers

Jay Jung avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.