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
- Clone the repository
- Go to the project:
$ cd webhook-sample
- Install dependencies
$ npm install
- 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.
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.