{"id":15383642,"url":"https://github.com/knownasilya/hapi-decorators","last_synced_at":"2025-05-05T04:03:17.983Z","repository":{"id":37851606,"uuid":"41576263","full_name":"knownasilya/hapi-decorators","owner":"knownasilya","description":"Decorators for HapiJS routes","archived":false,"fork":false,"pushed_at":"2023-01-27T04:30:45.000Z","size":1721,"stargazers_count":63,"open_issues_count":13,"forks_count":9,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-30T21:41:33.809Z","etag":null,"topics":["decorators","hapi","hapi-decorators","nodejs"],"latest_commit_sha":null,"homepage":"http://knownasilya.github.io/hapi-decorators","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/knownasilya.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"knownasilya"}},"created_at":"2015-08-29T01:28:06.000Z","updated_at":"2023-11-03T17:11:51.000Z","dependencies_parsed_at":"2023-02-15T05:15:48.725Z","dependency_job_id":null,"html_url":"https://github.com/knownasilya/hapi-decorators","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knownasilya%2Fhapi-decorators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knownasilya%2Fhapi-decorators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knownasilya%2Fhapi-decorators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knownasilya%2Fhapi-decorators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knownasilya","download_url":"https://codeload.github.com/knownasilya/hapi-decorators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251815461,"owners_count":21648369,"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","hapi","hapi-decorators","nodejs"],"created_at":"2024-10-01T14:39:03.325Z","updated_at":"2025-05-05T04:03:17.954Z","avatar_url":"https://github.com/knownasilya.png","language":"JavaScript","funding_links":["https://github.com/sponsors/knownasilya"],"categories":[],"sub_categories":[],"readme":"# hapi-decorators\n\nDecorators for HapiJS routes.\nHeavily inspired and borrowed from https://github.com/stewartml/express-decorators\n\nGreat to mix with https://github.com/jayphelps/core-decorators.js\n\n[![npm version](https://badge.fury.io/js/hapi-decorators.svg)](http://badge.fury.io/js/hapi-decorators)\n[![Build Status](https://travis-ci.org/knownasilya/hapi-decorators.svg)](https://travis-ci.org/knownasilya/hapi-decorators)\n[![Coverage Status](https://coveralls.io/repos/knownasilya/hapi-decorators/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/knownasilya/hapi-decorators?branch=master)\n\n## Usage\n\nPrerequisits:\n\n- Hapi 18.4+ (Use 1.x for Hapi 17)\n- Node 8+ (Use 1.x for Node 6)\n\n```sh\nnpm install --save hapi-decorators\n```\n\n```js\nimport {\n  get,\n  controller\n} from 'hapi-decorators'\nimport Hapi from '@hapi/hapi'\n\nconst server = new Hapi.Server()\n\nserver.connection({\n  host: 'localhost',\n  port: 3000\n})\n\n// Define your endpoint controller\n@controller('/hello')\nclass TestController {\n  constructor(target) {\n    this.target = target\n  }\n\n  @get('/world')\n  sayHello(request, reply) {\n    reply({ message: `hello, ${this.target}` })\n  }\n}\n\n// InitializeController\nlet test = new TestController('world')\n\n// Add Test Controller routes to server\nserver.route(test.routes())\n\n// Start the server\nserver.start((err) =\u003e {\n  if (err) throw err\n  console.log(`Server running at: ${server.info.uri}`)\n})\n```\n\n### Setup Babel\n\nRun the above script with the following command, after installing [babel].\n\n```no-highlight\nbabel-node --optional es7.decorators,es7.objectRestSpread index.js\n```\n\nNote: Decorators are currently unsupported in Babel 6. To work around that [issue]\nuse the [transform-decorators-legacy] plugin. See this [post] for detailed instructions.\n\n\n## Decorators\n\n### `@controller(basePath)`\n\n**REQUIRED** This decorator is required at the class level, since it processes the other decorators, and adds\nthe `instance.routes()` function, which returns the routes that can be used with Hapi, e.g. `server.routes(users.routes())`.\n\n\n### `@route(method, path)`\n\nThis decorator should be attached to a method of a class, e.g.\n\n```js\n@controller('/users')\nclass Users {\n  @route('post', '/')\n  newUser(request, reply) {\n    reply([])\n  }\n}\n```\n\n**Helper Decorators**\n\n* `@get(path)`\n* `@post(path)`\n* `@put(path)`\n* `@patch(path)`\n* `@delete(path)`\n* `@del(path)`\n* `@all(path)`\n\nThese are shortcuts for `@route(method, path)` where `@get('/revoke')` would be `@route('get', '/revoke')`.\n\n### `@options(options)`\n\nOverall options setting if none of the other decorators are sufficient.\n\n### `@validate(validateConfig)`\n\nAdd a validation object for the different types, except for the response.\n`config` is an object, with keys for the different types, e.g. `payload`.\n\n### `@cache(cacheConfig)`\n\nCache settings for the route config object.\n\n### `@pre(preArray)`\n\nSet prerequisite middleware array for a given route.\nExpects an array, but if passed something else, it will put it into the pre array.\n\n[babel]: https://www.npmjs.com/package/babel\n[transform-decorators-legacy]: https://www.npmjs.com/package/babel-plugin-transform-decorators-legacy\n[issue]: https://phabricator.babeljs.io/T2645\n[post]: http://technologyadvice.github.io/es7-decorators-babel6\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknownasilya%2Fhapi-decorators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknownasilya%2Fhapi-decorators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknownasilya%2Fhapi-decorators/lists"}