{"id":14969206,"url":"https://github.com/l2jliga/fastify-decorators","last_synced_at":"2025-05-15T02:09:29.514Z","repository":{"id":34880294,"uuid":"186095740","full_name":"L2jLiga/fastify-decorators","owner":"L2jLiga","description":"Set of Typescript decorators to build Fastify server with controllers, services and hooks","archived":false,"fork":false,"pushed_at":"2025-01-21T22:11:55.000Z","size":6641,"stargazers_count":300,"open_issues_count":15,"forks_count":26,"subscribers_count":5,"default_branch":"v4","last_synced_at":"2025-05-14T07:55:11.975Z","etag":null,"topics":["decorators","dependency-injection","fastify","fastify-plugin","request-handler","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/L2jLiga.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-11T06:19:35.000Z","updated_at":"2025-04-25T16:31:10.000Z","dependencies_parsed_at":"2023-01-15T10:01:10.395Z","dependency_job_id":"4aaebed1-35e0-47db-9e28-1d248bb9f7b9","html_url":"https://github.com/L2jLiga/fastify-decorators","commit_stats":{"total_commits":1156,"total_committers":9,"mean_commits":"128.44444444444446","dds":0.3728373702422145,"last_synced_commit":"de900fef268df64209a6342227477dc7e757a9c3"},"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L2jLiga%2Ffastify-decorators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L2jLiga%2Ffastify-decorators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L2jLiga%2Ffastify-decorators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L2jLiga%2Ffastify-decorators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/L2jLiga","download_url":"https://codeload.github.com/L2jLiga/fastify-decorators/tar.gz/refs/heads/v4","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254259384,"owners_count":22040820,"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":["decorators","dependency-injection","fastify","fastify-plugin","request-handler","typescript"],"created_at":"2024-09-24T13:41:21.694Z","updated_at":"2025-05-15T02:09:29.498Z","avatar_url":"https://github.com/L2jLiga.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Fastify decorators](./assets/logo.png)](https://github.com/L2jLiga/fastify-decorators)\n\n[![npm version](https://badge.fury.io/js/fastify-decorators.svg?colorB=brightgreen)](https://www.npmjs.com/package/fastify-decorators)\n[![npm](https://img.shields.io/npm/dm/fastify-decorators.svg?colorB=brightgreen)](https://www.npmjs.com/package/fastify-decorators)\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)\n[![Node.js CI](https://github.com/L2jLiga/fastify-decorators/actions/workflows/nodejs.yml/badge.svg)](https://github.com/L2jLiga/fastify-decorators/actions/workflows/nodejs.yml)\n[![codecov](https://codecov.io/gh/L2jLiga/fastify-decorators/branch/v4/graph/badge.svg)](https://codecov.io/gh/L2jLiga/fastify-decorators)\n\n\u003e **Framework aimed to provide useful TypeScript decorators to implement controllers, services and request handlers, built with [Fastify].**\n\n## Benefits\n\n- **Fastify compatible** - Built with [Fastify] and supports all its features and plugins\n  - **JSON Schema validation** - Build [JSON Schemas](https://json-schema.org/) to validate and speedup your requests and replies\n  - **High performance** - Framework adds as less overhead to Fastify as it can\n- **Highly customizable** - Create your controllers, services and their methods as you wish\n- **100% TypeScript** - Written in [TypeScript](https://www.typescriptlang.org/) and comes with all the required typings\n- **Plugins** - Library provides APIs to extend its functionality\n  - [**Simple DI**](./plugins/simple-di) - Provides simple Dependency Injection interface to bind your services\n  - [**TypeDI**](./plugins/typedi) - Provides integration with [TypeDI](https://npmjs.com/package/typedi)\n\n## Documentation\n\n- [Getting started](#getting-started)\n- [Bootstrapping]\n- [Controllers]\n- [Request Handlers]\n- [Testing]\n- [Plugins Development]\n- [Migration guide (V4)]\n\n## Fastify versions support\n\n| Fastify Decorators |  Fastify  |\n| :----------------: | :-------: |\n|        1.x         |    2.x    |\n|        2.x         |    2.x    |\n|      \u003c 3.12.x      |    3.x    |\n|     \u003e= 3.12.x      | 3.x \u0026 4.x |\n|        4.x         |    4.x    |\n\n## Alternatives\n\n- **[NestJS]** - A progressive Node.js framework for building efficient, reliable and scalable server-side applications.\n- **[Fastify Resty]** - Modern and declarative REST API framework for superfast and oversimplification backend development, build on top of Fastify and TypeScript.\n\n## Getting started\n\nHello! Thank you for checking out fastify-decorators!\n\nThis documents aims to be gentle introduction to the fastify-decorators and its usages.\n\n### Prerequisites\n\n- Typescript\n- Fastify\n- typings for NodeJS (`@types/node` package installed)\n\n### Install\n\nInstall with npm\n\n```\nnpm i fastify-decorators --save\n```\n\nInstall with yarn\n\n```\nyarn add fastify-decorators\n```\n\n### Additional TypeScript configuration\n\nFastify-decorators requires `experimentalDecorators` feature to be enabled. For this you need to update your TypeScript config:\n\n_tsconfig.json_:\n\n```json\n{\n  \"compilerOptions\": {\n    \"experimentalDecorators\": true\n  }\n}\n```\n\n_Note_: if you struggle which `target` please refer to table below:\n\n| Node version | target |\n| ------------ | ------ |\n| 14.x         | es2020 |\n| 16.x         | es2021 |\n| 18.x         | es2022 |\n\n`fastify-decorators` itself use `\"target\": \"es2018\"` to support NodeJS 10+ (see [Node.js ES2018 Support]).\n\n### Your first server\n\n#### Request handler way\n\nLet's write your first server with request handler:\n\n_Project structure_:\n\n```\n ├── index.ts\n ├── handlers\n │    └── first.handler.ts\n └── tsconfig.json\n```\n\n_index.ts_:\n\n```ts\nimport { bootstrap } from 'fastify-decorators';\n\n// Require the framework and instantiate it\nconst instance = require('fastify')();\n\n// Register handlers auto-bootstrap\ninstance.register(bootstrap, {\n  // Specify directory with our handler\n  directory: new URL(`handlers`, import.meta.url),\n\n  // Specify mask to match only our handler\n  mask: /\\.handler\\./,\n});\n\n// Run the server!\ninstance.listen(3000);\n```\n\n_handlers/first.handler.ts_:\n\n```ts\nimport { GET, RequestHandler } from 'fastify-decorators';\n\n@GET({\n  url: '/hello',\n})\nexport default class FirstHandler extends RequestHandler {\n  async handle() {\n    return 'Hello world!';\n  }\n}\n```\n\n#### Controllers way\n\nfastify-decorators also provides way to build controllers with multiple handlers:\n\n_Project structure_:\n\n```\n ├── index.ts\n ├── controllers\n │    └── first.controller.ts\n └── tsconfig.json\n```\n\n_index.ts_:\n\n```ts\nimport { bootstrap } from 'fastify-decorators';\n\n// Require the framework and instantiate it\nconst instance = require('fastify')();\n\n// Register handlers auto-bootstrap\ninstance.register(bootstrap, {\n  // Specify directory with our controllers\n  directory: new URL(`controllers`, import.meta.url),\n\n  // Specify mask to match only our controllers\n  mask: /\\.controller\\./,\n});\n\n// Run the server!\ninstance.listen(3000);\n```\n\n_controllers/first.controller.ts_:\n\n```ts\nimport { Controller, GET } from 'fastify-decorators';\n\n@Controller({ route: '/' })\nexport default class FirstController {\n  @GET({ url: '/hello' })\n  async helloHandler() {\n    return 'Hello world!';\n  }\n\n  @GET({ url: '/goodbye' })\n  async goodbyeHandler() {\n    return 'Bye-bye!';\n  }\n}\n```\n\nAlso, we need to enable `experimentalDecorators` feature in our TypeScript config\n\n_tsconfig.json_:\n\n```json\n{\n  \"compilerOptions\": {\n    \"experimentalDecorators\": true\n  }\n}\n```\n\n### Build and run server\n\nAfter all our files done we have to build server before we can run it:\n\n1. Add to our package.json script to build server:\n\n   ```\n   \"scripts\": {\n     \"build\": \"tsc\"\n   }\n   ```\n\n1. Run build script\n   With npm:\n\n   ```\n   npm run build\n   ```\n\n   with yarn:\n\n   ```\n   yarn build\n   ```\n\n1. Start server\n   ```\n   node index.ts\n   ```\n\nAwesome, that was easy.\n\n[node.js es2018 support]: https://node.green/#ES2018\n\n## License\n\nThis project licensed under [MIT License]\n\n[fastify]: https://npmjs.org/package/fastify\n[mit license]: https://github.com/L2jLiga/fastify-decorators/blob/master/LICENSE\n[nestjs]: https://nestjs.com/\n[fastify resty]: https://github.com/FastifyResty/fastify-resty\n[bootstrapping]: ./docs/Bootstrapping.md\n[controllers]: ./docs/Controllers.md\n[request handlers]: ./docs/Request%20Handlers.md\n[testing]: ./docs/Testing.md\n[migration guide (v4)]: ./docs/Migration%20to%20v4.md\n[Plugins Development]: ./docs/Plugins%20Development.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl2jliga%2Ffastify-decorators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fl2jliga%2Ffastify-decorators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl2jliga%2Ffastify-decorators/lists"}