{"id":21964407,"url":"https://github.com/beliven-it/fastify-crud-generator","last_synced_at":"2025-04-24T01:40:39.476Z","repository":{"id":36977463,"uuid":"287568263","full_name":"beliven-it/fastify-crud-generator","owner":"beliven-it","description":"A plugin to rapidly generate CRUD routes for any entity","archived":false,"fork":false,"pushed_at":"2024-03-27T04:28:41.000Z","size":1667,"stargazers_count":21,"open_issues_count":3,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-24T19:48:26.923Z","etag":null,"topics":["crud","fastify","generator","plugin","rest","routes"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/beliven-it.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-14T15:43:17.000Z","updated_at":"2024-06-19T16:48:01.225Z","dependencies_parsed_at":"2024-03-23T13:38:56.099Z","dependency_job_id":"f8c5edcb-4072-4bdc-983f-e6fbbe2b67df","html_url":"https://github.com/beliven-it/fastify-crud-generator","commit_stats":{"total_commits":75,"total_committers":6,"mean_commits":12.5,"dds":0.64,"last_synced_commit":"72ecb02fd62961ff48775a834633c1ed6b378689"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beliven-it%2Ffastify-crud-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beliven-it%2Ffastify-crud-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beliven-it%2Ffastify-crud-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beliven-it%2Ffastify-crud-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beliven-it","download_url":"https://codeload.github.com/beliven-it/fastify-crud-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250545472,"owners_count":21448213,"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":["crud","fastify","generator","plugin","rest","routes"],"created_at":"2024-11-29T12:07:57.181Z","updated_at":"2025-04-24T01:40:39.407Z","avatar_url":"https://github.com/beliven-it.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# fastify-crud-generator\n\nA plugin to rapidly generate CRUD routes for any entity\n\n[![Node.js CI](https://github.com/beliven-it/fastify-crud-generator/actions/workflows/node.js.yml/badge.svg)](https://github.com/beliven-it/fastify-crud-generator/actions/workflows/node.js.yml)\n\n## Install\n\n```bash\nnpm i --save fastify-crud-generator\n```\n\n## Usage\n\n```js\nfastify\n  .register(require('fastify-crud-generator'), {\n    prefix: '/products',\n    controller: ...\n  })\n  .after(() =\u003e console.log(fastify.printRoutes()))\n```\n\nIt can be registered as many times as you need, with different prefix:\n\n```js\nconst crud = require('fastify-crud-generator')\n\nfastify\n  .register(crud, {\n    prefix: '/products',\n    controller: ...\n  })\n  .register(crud, {\n    prefix: '/orders',\n    controller: ...\n  })\n  .after(() =\u003e console.log(fastify.printRoutes()))\n```\n\nBy default, the following routes are supported:\n\n```\nGET    (prefix)/\nPOST   (prefix)/\nGET    (prefix)/:id\nPATCH  (prefix)/:id\nDELETE (prefix)/:id\n```\n\n## Options\n\nWhen registering the plugin in your app, you can pass\nthe following options to fine-tuning the CRUD routes generation:\n\n| Name                | Description                                                         |\n|---------------------|---------------------------------------------------------------------|\n| `prefix`            | Add a prefix to all generated routes.                               |\n| `controller`        | (MANDATORY) A controller object providing handlers for each route.  |\n| `list`              | Route options for **list** action.                                  |\n| `create`            | Route options for **create** action.                                |\n| `view`              | Route options for **view** action.                                  |\n| `update`            | Route options for **update** action.                                |\n| `delete`            | Route options for **delete** action.                                |\n\n### Prefix\n\nThis option can be used to prefix all routes with a common path, usually the plural\nname of the entity according to REST best practices:\n\n```js\n{\n  prefix: '/products'\n}\n```\n\nThe `prefix` option can also be used to define API version for the generated routes:\n\n```js\n{\n  prefix: '/v1/products'\n}\n```\n\n**NOTE:** if no `prefix` is specified, all routes will be added at the root level.\n\n### Controller\n\nThis is the only **mandatory** option during the plugin registration.\n\nA `controller` object provides the route handlers used to implement the classic\nCRUD actions for the registered entity (list, create, view, update, delete).\n\nPassing an external `controller` object allows the maximum flexibility in terms\nof business logic and underlying data layer for any entity (*e.g. SQL, NoSQL,\nfile storage, etc.*)\n\n```js\n{\n  prefix: '/products',\n  controller: productController\n}\n```\n\nA `controller` object should implement the following interface:\n\n```js\n{\n  list: async (req, reply) =\u003e { ... },\n  create: async (req, reply) =\u003e { ... },\n  view: async (req, reply) =\u003e { ... },\n  update: async (req, reply) =\u003e { ... },\n  delete: async (req, reply) =\u003e { ... }\n}\n```\n\nPlease note you're not forced to implement all supported methods: you can choose\nto implement only those needed by your resource.\n\nNot implementing a method of the interface will automatically disable the\ncorresponding route.\n\nAll methods accept a `req / reply` argument pair, which are the original\n[request](https://www.fastify.io/docs/latest/Request/) and\n[reply](https://www.fastify.io/docs/latest/Reply/) objects\npassed to the route.\n\n### Route options\n\nThe `list`, `create`, `view`, `update` and `delete` options allow to fine tune\nthe generated routes according to the available configuration provided by Fastify.\n\nTake a look at the [official documentation](https://www.fastify.io/docs/latest/Routes/#options)\nfor more details.\n\n## Test\n\n```bash\nnpm test\n```\n\n## Acknowledgements\n\nThis project is inspired by:\n\n* [fastify-autocrud](https://www.npmjs.com/package/fastify-autocrud)\n\nAnd kindly sponsored by:\n\n[![Beliven](https://assets.beliven.com/brand/logo_pos_color.svg)](https://www.beliven.com)\n\n## License\n\nLicensed under [MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeliven-it%2Ffastify-crud-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeliven-it%2Ffastify-crud-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeliven-it%2Ffastify-crud-generator/lists"}