jhnferraris / webhook-sample

Home Page:https://webhook-sample-eight.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

webhook-sample

This is a sample of a webhook that can be used on any system (e.g. gateways) that will notify your application via a POST endpoint

How to call the webhook using the sample

Setup

  1. Clone the repository
  2. Go to the project: $ cd webhook-sample
  3. Install dependencies $ npm install
  4. Run the server $ npm start

Calling the webhook

The code:

const express = require('express');
const bodyParser = require('body-parser');
const app = express();

app.use(bodyParser.json())

app.post('/webhook', async (req, res) => {
  // TODO: You will have to implement the logic of this method.
  // processWebhookNotificationData(req.body);
  res.send({
    processWebhookData: 'success',
  })
});

app.listen(8080, () => console.log(`Listening on port ${8080}!`));

The sample code above (see also index.js) will spin up a server that will run on port 8080 on your localhost (When you go to production, you will have to use a different domain). You can either do a curl command or use a curl client application (e.g. POSTMAN) for the sake of testing.

Screenshot of Postman Screen Shot 2022-05-19 at 8 43 35 AM

On live applications, webhook endpoints are typically registered on the 3rd party APIs (e.g. payment service providers) to enable these APIs to notify their client's applications.

About

https://webhook-sample-eight.vercel.app


Languages

Language:JavaScript 100.0%