Giter VIP home page Giter VIP logo

http-notification-system's Introduction

HTTP notification system utilizing AWS SNS and NestJS Framework.

Setup

Installation

$ npm install

Environmental Setup

Properties (.env)

  • Below are some example values for the environment file .env
  • PORT is the port that this application will listen on
  • AWS_REGION is the location of your VPC
  • AWS_ARN When a topic is created, Amazon SNS will assign a unique ARN(Amazon Resource Name) to the topic, which include the service name (SNS), region, AWS ID of the user and the topic name. The ARN will return as part of the API call to create a topic. The following is the ARN for a topic named "mytopic" created by a user with the AWS account ID "1234567890121" and hosted in the "US East region": arn:aws:sns:us-east-1:1234567890123456:mytopic. Using the above ARN as an example, we will only be adding arn:aws:sns:us-east-1:1234567890123456: as our environment variable.

For more information on how to create topics on Amazon SNS, see Getting Started with Amazon SNS

  PORT=3000
  AWS_REGION="us-east-1"
  AWS_ARN="arn:aws:sns:us-east-1:1234567890123456:"

Credentials

AWS SDK will be looking for credentials. The AWS credentials data is saved in a shared file used by the SDK. The shared credentials file is named "credentials". Where you keep the shared credentials file depends on your operating system:

  • The shared credentials file on Linux, Unix, and macOS: ~/.aws/credentials
  • The shared credentials file on Windows: C:\Users\USER_NAME\ .aws\credentials

If you do not already have a shared credentials file, see Getting Your Credentials. Once you follow those instructions, you should see text similar to the following in the credentials file, where <YOUR_ACCESS_KEY_ID> is your access key ID and <YOUR_SECRET_ACCESS_KEY> is your secret access key:

  [sns_profile]
  aws_access_key_id = <YOUR_ACCESS_KEY_ID>
  aws_secret_access_key = <YOUR_SECRET_ACCESS_KEY>
  region = <AWS_REGION>

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

API Enpoints

Registered topic names

  • topic1
  • topic2

Base URL

Subscribe Endpoint

  • method: POST
  • URL: /subscribe/{topic}

Sample Request Body

  {
      "url": "http://mysubscriber.test"
  }

Sample Request Headers

    {
        "Content-Type: application/json"
    }

Sample Respone

  {
      "url": "http://mysubscriber.test",
      "topic": "topic1"
  }

Expample 1 - valid topic and URL

Request
  curl --location --request POST 'http://localhost:3000/subscribe/topic1' \
  --header 'Content-Type: application/json' \
  --data-raw '{
      "url": "http://google.com"
  }'
Response
  {
      "topic": "topic1",
      "url": "http://google.com"
  }

Expample 2 - invalid URL

Request
  curl --location --request POST 'http://localhost:3000/subscribe/topic1' \
  --header 'Content-Type: application/json' \
  --data-raw '{
      "url": "vialung"
  }'
Response
  {
    "status": 400,
    "error": "InvalidParameter"
  }

Expample 3 - invalid Topic

Request
  curl --location --request POST 'http://localhost:3000/subscribe/topic3' \
  --header 'Content-Type: application/json' \
  --data-raw '{
      "url": "http://google.com"
  }'
Response
  {
    "status": 404,
    "error": "NotFound"
  }

Publish Endpoint

  • method: POST
  • URL: /publish/{topic}

Sample Request Body

  {
      "message": "{url: 'http://mysubscriber.test' }"
  }

Sample Request Headers

    {
        "Content-Type: application/json"
    }

Sample Respone

  "0e235ad7-6314-533b-b2f1-00c95eef87b0"

Expample 1 - valid topic

Request
  curl --location --request POST 'http://localhost:3000/publish/topic1' \
  --header 'Content-Type: application/json' \
  --data-raw '{
      "message": {"hello": "world"}
  }'
Response
  "7019afbe-3efb-5992-9003-f5a38a4a48f5"

Expample 2 - invalid topic

Request
  curl --location --request POST 'http://localhost:3000/publish/topic3' \
  --header 'Content-Type: application/json' \
  --data-raw '{
      "message": {"hello": "world"}
  }'
Response
  {
    "status": 404,
    "error": "NotFound"
  }

Expample 3 - empty body

Request
  curl --location --request POST 'http://localhost:3000/publish/topic3' \
  --header 'Content-Type: application/json' \
  --data-raw '{
      
  }'
Response
  {
    "status": 400,
    "error": "ValidationError"
  }

License

Nest is MIT licensed.

http-notification-system's People

Contributors

aditechgh avatar

Watchers

 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.