Webhooks Microservice API
WebHooks Microservice. Built with NodeJs
Table of Contents
- Introduction
- Features
- Architecture
- Usage Instructions
- Check Routes
- Tasks
- Development
- 1. Product
-
[2. Helper (Tester Target)](#2-helper-testertarget)
- Product
- NPM scripts
Introduction
This is a Implementation Webhooks Service using Moleculer
( Progressive microservices framework for Node.js. ) and Express
( Back-End for Node.js )
In the terminal, try the following commands:
nodes
- List all connected nodes.actions
- List all registered service actions.call greeter.hello
- Call thegreeter.hello
action.call greeter.welcome --name John
- Call thegreeter.welcome
action with thename
parameter.call "webhooks.trigger" --ipadr "192.12.445.55"
- Call thewebhooks.trigger
action with theipadr
parameter.
Features
- Register, Update, Delete, and List Web-Hooks
- URL Validation on Web-Hooks
- on Register
- on Update
- Concurrent Requests
Architecture
Usage Instructions
This is a Moleculer-based microservices project. Generated with the Moleculer CLI.
Install
git clone https://github.com/Swarag-N/Webhooks-Microservice.git
cd Webhooks-Microservice
Start locally
To start locally, you need to running a MongoDB server on localhost.
npm install
npm start
Open the http://localhost:3000/ URL in your browser.
Start in Docker
Running as microservices All services are running in separated containers, communicate via NATS & use Traefik reverse proxy.
npm run dc:up
Open the http://docker-machine:3000/ URL in your browser.
Development locally
Running MongoDB is required on localhost!
npm run dev
Target Server
Basic HTTP Servers to capture the response
npm run targets
- Open the http://localhost:4000/ URL in your browser.
- Open the http://localhost:4001/ URL in your browser.
- Open the http://localhost:4002/ URL in your browser.
- Open the http://localhost:4003/ URL in your browser.
- Open the http://localhost:4004/ URL in your browser.
Check Routes
Locally
- Install Dependencies (Dev and Production)
npm ci
- Start Target Servers : 5 Http Servers will Start
- PORT [4000 … 4004]
- Logs the request
- Health Check
http://localhost:4000/
npm run targets
-
Import Postman collections of API Service from
docs
folder -
Start Service
npm run dev
Start the project with npm run dev
command.
After starting, open the http://localhost:3000/list URL in your browser.
call "webhooks.trigger" --ipadr "192.12.445.55"
- Call the webhooks.trigger
action with the ipadr
parameter
o/p
┌───────────┬─────────────────┐
│ (index) │ Values │
├───────────┼─────────────────┤
│ ipadr │ '192.12.445.55' │
│ timeStamp │ 1626537496624 │
└───────────┴─────────────────┘
┌───────────┬─────────────────┐
│ (index) │ Values │
├───────────┼─────────────────┤
│ ipadr │ '192.12.445.55' │
│ timeStamp │ 1626537496624 │
└───────────┴─────────────────┘
Docker Service
-
Import Postman collections of API Service from
docs
folder -
Start Service
npm run dc:up
NOTE: Local Network is different from Internal Network, give external sites as Input
Tasks
- Collect Info
- Molecular
- Understand Problem Statement
- Development
- DB Seed
- Add WebHook Servers
Development
Two Servers
- Microservice App to Store and Trigger WebHooks
- Web-Hooks Receiver
1. Product
- API Gateway
- DB
- Message Broker
- Web-Hook Trigger Initiator
2. Helper (Tester|Target)
- Listens for Requests
Product
- api: API Gateway services
- greeter: Sample service with
hello
andwelcome
actions. - webhooks: Service with actions to register and create triggers on webHooks.
Services
Microservice using Moleculer Framework with a Backend using Express framework implemneted Webhooks funtionality.
Check docs\demo.md
for API response for bellow EndPoints
API Service
- Routes
admin
- Create :
/register
add new webhooks - Read :
/list
list registerd webhooks - Update :
/update
update registerd webhook - Delete :
/delete
delete registerd webhook
- Create :
- Trigger :
/ip
initate requests to all registerd webhooks- Calls the
trigger
action exposed by thewebhooks microservice
.
- Calls the
- Routes
webhooks microservice
- Actions
webhooks.register
- URL Validation before registering Webhook
webhooks.list
webhooks.update
- URL Validation before updating Webhook
webhooks.delete
webhooks.trigger
- Initate requests concurrently in batches
- Actions
Actions
Resources
An Introduction to Moleculer JS
moleculerjs/moleculer-examples
Useful links
- Moleculer website: https://moleculer.services/
- Moleculer Documentation: https://moleculer.services/docs/0.14/
NPM scripts
npm run dev
: Start development mode (load all services locally with hot-reload & REPL)npm run start
: Start production mode (setSERVICES
env variable to load certain services)npm run cli
: Start a CLI and connect to production. Don’t forget to set production namespace with--ns
argument in scriptnpm run lint
: Run ESLintnpm run ci
: Run continuous test mode with watchingnpm test
: Run tests & generate coverage report