CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
Write-Plugin.md105 linesDownload Raw Back to Guides
1<h1 style="text-align: center;">Fastify</h1>2 3# How to write a good plugin4First, thank you for deciding to write a plugin for Fastify. Fastify is a5minimal framework and plugins are its strength, so thank you.6 7The core principles of Fastify are performance, low overhead, and providing a8good experience to our users. When writing a plugin, it is important to keep9these principles in mind. Therefore, in this document, we will analyze what10characterizes a quality plugin.11 12*Need some inspiration? You can use the label ["plugin13suggestion"](https://github.com/fastify/fastify/issues?q=is%3Aissue+is%3Aopen+label%3A%22plugin+suggestion%22)14in our issue tracker!*15 16## Code17Fastify uses different techniques to optimize its code, many of them are18documented in our Guides. We highly recommend you read [the hitchhiker's guide19to plugins](./Plugins-Guide.md) to discover all the APIs you can use to build20your plugin and learn how to use them.21 22Do you have a question or need some advice? We are more than happy to help you!23Just open an issue in our [help repository](https://github.com/fastify/help).24 25Once you submit a plugin to our [ecosystem list](./Ecosystem.md), we will review26your code and help you improve it if necessary.27 28## Documentation29Documentation is extremely important. If your plugin is not well documented we30will not accept it to the ecosystem list. Lack of quality documentation makes it31more difficult for people to use your plugin, and will likely result in it going32unused.33 34If you want to see some good examples of how to document a plugin take a look35at:36- [`@fastify/caching`](https://github.com/fastify/fastify-caching)37- [`@fastify/compress`](https://github.com/fastify/fastify-compress)38- [`@fastify/cookie`](https://github.com/fastify/fastify-cookie)39- [`@fastify/under-pressure`](https://github.com/fastify/under-pressure)40- [`@fastify/view`](https://github.com/fastify/point-of-view)41 42## License43You can license your plugin as you prefer, we do not enforce any kind of44license.45 46We prefer the [MIT license](https://choosealicense.com/licenses/mit/) because we47think it allows more people to use the code freely. For a list of alternative48licenses see the [OSI list](https://opensource.org/licenses) or GitHub's49[choosealicense.com](https://choosealicense.com/).50 51## Examples52Always put an example file in your repository. Examples are very helpful for53users and give a very fast way to test your plugin. Your users will be grateful.54 55## Test56It is extremely important that a plugin is thoroughly tested to verify that is57working properly.58 59A plugin without tests will not be accepted to the ecosystem list. A lack of60tests does not inspire trust nor guarantee that the code will continue to work61among different versions of its dependencies.62 63We do not enforce any testing library. We use [`node:test`](https://nodejs.org/api/test.html)64since it offers out-of-the-box parallel testing and code coverage, but it is up65to you to choose your library of preference.66We highly recommend you read the [Plugin Testing](./Testing.md#plugins) to67learn about how to test your plugins.68 69## Code Linter70It is not mandatory, but we highly recommend you use a code linter in your71plugin. It will ensure a consistent code style and help you to avoid many72errors.73 74We use [`standard`](https://standardjs.com/) since it works without the need to75configure it and is very easy to integrate into a test suite.76 77## Continuous Integration78It is not mandatory, but if you release your code as open source, it helps to79use Continuous Integration to ensure contributions do not break your plugin and80to show that the plugin works as intended. Both81[CircleCI](https://circleci.com/) and [GitHub82Actions](https://github.com/features/actions) are free for open source projects83and easy to set up.84 85In addition, you can enable services like [Dependabot](https://github.com/dependabot),86which will help you keep your dependencies up to date and discover if a new87release of Fastify has some issues with your plugin.88 89## Let's start!90Awesome, now you know everything you need to know about how to write a good91plugin for Fastify! After you have built one (or more!) let us know! We will add92it to the [ecosystem](https://github.com/fastify/fastify#ecosystem) section of93our documentation!94 95If you want to see some real world examples, check out:96- [`@fastify/view`](https://github.com/fastify/point-of-view) Templates97  rendering (*ejs, pug, handlebars, marko*) plugin support for Fastify.98- [`@fastify/mongodb`](https://github.com/fastify/fastify-mongodb) Fastify99  MongoDB connection plugin, with this you can share the same MongoDB connection100  pool in every part of your server.101- [`@fastify/multipart`](https://github.com/fastify/fastify-multipart) Multipart102  support for Fastify.103- [`@fastify/helmet`](https://github.com/fastify/fastify-helmet) Important104  security headers for Fastify.105