{"id":22485408,"url":"https://github.com/smartiniOnGitHub/fastify-webhook","last_synced_at":"2025-08-02T18:32:22.151Z","repository":{"id":48408999,"uuid":"126216033","full_name":"smartiniOnGitHub/fastify-webhook","owner":"smartiniOnGitHub","description":"Fastify Plugin to serve webhooks with some default settings","archived":false,"fork":false,"pushed_at":"2023-01-28T18:30:53.000Z","size":88,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-20T04:28:12.629Z","etag":null,"topics":["fastify","fastify-plugin","webhook","webhooks"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smartiniOnGitHub.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-21T17:25:12.000Z","updated_at":"2024-06-16T05:56:21.000Z","dependencies_parsed_at":"2023-02-15T18:16:06.957Z","dependency_job_id":null,"html_url":"https://github.com/smartiniOnGitHub/fastify-webhook","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartiniOnGitHub%2Ffastify-webhook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartiniOnGitHub%2Ffastify-webhook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartiniOnGitHub%2Ffastify-webhook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartiniOnGitHub%2Ffastify-webhook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smartiniOnGitHub","download_url":"https://codeload.github.com/smartiniOnGitHub/fastify-webhook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228499952,"owners_count":17929988,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastify","fastify-plugin","webhook","webhooks"],"created_at":"2024-12-06T17:12:32.887Z","updated_at":"2024-12-06T17:14:24.722Z","avatar_url":"https://github.com/smartiniOnGitHub.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# fastify-webhook\r\n\r\n  [![NPM Version](https://img.shields.io/npm/v/fastify-webhook.svg?style=flat)](https://npmjs.org/package/fastify-webhook/)\r\n  [![NPM Downloads](https://img.shields.io/npm/dm/fastify-webhook.svg?style=flat)](https://npmjs.org/package/fastify-webhook/)\r\n  [![Code Style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)\r\n  [![license - APACHE-2.0](https://img.shields.io/npm/l/fastify-webhook.svg)](http://opensource.org/licenses/APACHE-2.0)\r\n\r\nFastify Plugin to serve webhooks with some useful default settings.\r\n\r\nWith this plugin, Fastify will have a route configured for `/webhook` POST requests.\r\n\r\n\r\n## Usage\r\n\r\n```js\r\nconst fastify = require('fastify')()\r\n\r\n// example without specifying options, returning a default webhook mapped to '/webhook' that only acknowledge the POST request\r\nfastify.register(require('fastify-webhook'))\r\n// or\r\n// example with custom webhook url and handler, and secret key\r\n// fastify.register(require('fastify-webhook'), {'url': '/custom-webhook', 'handler': myWebhookHandler, 'secretKey': 'secret key'})\r\n//\r\n// note that to use one of handlers bundled with the plugin, you need to get a reference to the plugin script 'src/handlers', and then as handler pass a reference to desired function, like:\r\n// const webhookHandlers = require('fastify-webhook/src/handlers') // get plugin handlers (optional)\r\n// const webhookPlugin = require('fastify-webhook')\r\n// fastify.register(webhookPlugin, { 'url': '/custom-webhook', 'handler': webhookHandlers.echo, 'secretKey': 'secret key'})\r\n//\r\n\r\nfastify.listen(3000)\r\n\r\n// To test, for example (in another terminal session) do:\r\n// curl http://127.0.0.1:3000/webhook -X POST -H 'Content-Type: application/json' -d '{\"payload\":\"test\"}' =\u003e returning a JSON dump of the given data, and no thrown error\r\n// in Windows you need to escape double quote char in the given json body, so do:\r\n// curl http://127.0.0.1:3000/webhook -X POST -H \"Content-Type: application/json\" -d \"{\\\"payload\\\":\\\"test\\\"}\"\r\n// or put data in a json file and pass with something like: '-d @body.json'\r\n```\r\n\r\nIn the [example](./example/) folder there are some simple server scripts that uses the plugin (inline but it's the same using it from npm registry).\r\n\r\n\r\n## Requirements\r\n\r\nFastify ^4.0.1 , Node.js 14 LTS (14.15.0) or later.\r\nNote that plugin releases 3.x are for Fastify 3.x, 4.x are for Fastify 4.x, etc.\r\n\r\n\r\n## Sources\r\n\r\nSource code is all inside main repo:\r\n[fastify-webhook](https://github.com/smartiniOnGitHub/fastify-webhook).\r\n\r\nDocumentation generated from source code (library API):\r\n[here](https://smartiniongithub.github.io/fastify-webhook/).\r\n\r\n\r\n## Note\r\n\r\nBy default the plugin map a default handler on the URI `/webhook` to be called via POST, otherwise it's possible to change via the setting 'url' in plugin options.\r\n\r\nThe plugin exposes some handlers, for common base operations (and webhook debug help).\r\nTo use one of them, before registering the plugin, you need to get a reference from its `src/handlers` source file;\r\nthen you can configure the desired one in the setting 'handler' in plugin options.\r\nThey are:\r\n- `acknowledge` (default handler) that simply acknowledge the request, and reply with a simple json response\r\n- `echo` it dumps the given input data in the (json) response\r\n- `logger` it dumps some info on the request using Fastify logger\r\nbut of course for a real world usage you need to specify your own handler function, with arguments '(request, reply)'.\r\nOtherwise you can use yours, with signature `function handler (request, reply)`.\r\n\r\nOther plugin options:\r\n- 'disableWebhook' (default false) to disable the registration of the route for the webhook\r\n- 'enableGetPlaceholder' (default false) to publish via GET a route with the same path of the webhook but returning an HTTP Error 405 Method Not Allowed\r\n- 'secretKey' (default null) to specify a string as secret key that callers of the webhook must provide, or webhook will reply with an error\r\n- 'preHandlers' is a list of functions to be used as preHandler in the specific route of the webhook; currently the list contains an internal function to check the secret key (if given); otherwise you can define and use yours, with signature `function preHandler (request, reply, done)`.\r\n\r\nNote that there is not a good general way to handle (usually user-specific) token in requests, so this is not managed via the plugin, but in examples and tests you can find some info.\r\n\r\n\r\n## License\r\n\r\nLicensed under [Apache-2.0](./LICENSE).\r\n\r\n----\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FsmartiniOnGitHub%2Ffastify-webhook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FsmartiniOnGitHub%2Ffastify-webhook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FsmartiniOnGitHub%2Ffastify-webhook/lists"}