Before we start working on the implementation of a webhook handler, we will take a look at handling authorization.

To guarantee that only your server is allowed to send data to your webhook handler, an authorization token is generated on creation of a webhook. The generated token will only be returned once and not be visible again.

Now that we know how the token is structured and what it is used for we can continue with implementing a webhook handler.

A webhook handler is just a simple POST endpoint that you need to implement at the URL you specified when creating a webhook.

const webhookToken ='fe944e318edb02b979d6bf0c87978b640c8e74e1cbfe36404386d33a5bbd8b66'const verification ='0c8e74e1cbfe36404386d33a5bbd8b66'
server.post('/blocks', jsonParser,(req, res)=>{// This will be fe944e318edb02b979d6bf0c87978b64const authorization = req.headers['authorization']// This will be authorization + verificationconst token = authorization + verification
// Make sure we block access if the token is invalid...if(token !== webhookToken){return res.status(401).send('Unauthorized!')}// the datetime of when the webhook was sent
console.log(req.body.created)// the data the webhook transfered, e.g. a block struct
console.log(req.body.data)// the type of event that was sent, e.g. block.forged
console.log(req.body.type)// do something with the above req.body datareturn res.status(200).send('Hello Webhook!')})