{"id":24383463,"url":"https://github.com/firstandthird/hapi-method-loader","last_synced_at":"2025-03-12T17:20:48.022Z","repository":{"id":53724295,"uuid":"43331377","full_name":"firstandthird/hapi-method-loader","owner":"firstandthird","description":"Hapi method loader","archived":false,"fork":false,"pushed_at":"2021-03-17T21:00:24.000Z","size":262,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-04T09:40:25.259Z","etag":null,"topics":["hapi-plugin"],"latest_commit_sha":null,"homepage":null,"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/firstandthird.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}},"created_at":"2015-09-28T22:49:00.000Z","updated_at":"2021-03-17T21:00:24.000Z","dependencies_parsed_at":"2022-09-23T12:50:43.774Z","dependency_job_id":null,"html_url":"https://github.com/firstandthird/hapi-method-loader","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-method-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-method-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-method-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-method-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firstandthird","download_url":"https://codeload.github.com/firstandthird/hapi-method-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243259029,"owners_count":20262381,"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":["hapi-plugin"],"created_at":"2025-01-19T10:14:33.121Z","updated_at":"2025-03-12T17:20:47.992Z","avatar_url":"https://github.com/firstandthird.png","language":"JavaScript","readme":"## hapi-method-loader   [![Build Status](https://travis-ci.org/firstandthird/hapi-method-loader.svg?branch=master)](https://travis-ci.org/firstandthird/hapi-method-loader)\n\nA plugin that automatically loads [hapi](https://hapi.dev/) server methods for you. Never type `server.method(....)` again!\n\n### Installation\n\n`npm install hapi-method-loader`\n\n### Usage\n\n```js\nserver.register({\n  register: require('hapi-method-loader'),\n  options: {}\n});\n```\n\nWill cause hapi to scan the _methods_ directory and import all the files it finds there as [server methods](https://hapi.dev/api/?v=20.1.0#-servermethods).\n\n### Method Files\n\nEach method should be a file in the _methods_ directory. Sub directories may be used for nested methods. File name will dictate method name.\n\n- Each file should export a _method_ function, which can take any parameters you want, return any value you want, and can be async or synchronous.  Inside the function the `this` keyword will be bound to the server.\n- Optionally you can include an _options_ object which will be passed on to hapi's [server.method](https://hapi.dev/api/?v=20.1.0#-servermethodname-method-options) function.\n- Optionally you can include a [Joi schema](https://www.npmjs.com/package/@hapi/joi) that will be read by [hapi-docs](https://github.com/firstandthird/hapi-docs) and made available in the server documentation.\n- Optionally you can include a _description_ string that will be read by [hapi-docs](https://github.com/firstandthird/hapi-docs).\n\nExample Method File:\n\n```js\nconst Joi = require('@hapi/joi');\nmodule.exports = {\n  method: function(name) {\n    // 'this' will be bound to the server:\n    this.log(`Hello ${name}!`);\n  },\n  options: {\n    cache: {\n      expiresIn: 60 * 60 * 1000\n    }\n  },\n  schema: Joi.object({\n    name: Joi.string().required()\n  }),\n  description: 'Greets the user by name'\n};\n```\n\nExample Directory Layout:\n\n```\n-methods/\n  -hello.js\n  -world.js\n  |-data/\n    |-dump.js\n    |-db/\n      |- fetch.js\n      |- put.js\n```\n\nWill result in the following server methods:\n- _server.methods.hello()_\n- _server.methods.world()_\n- _server.methods.data.dump()_\n- _server.methods.data.db.fetch()_\n- _server.methods.data.db.put()_\n\n\n## Plugin Options\n\nThe following options can be passed when the plugin is registered with hapi:\n\n- _path_\n\n  By default hapi-method-loader will look for your methods in a directory named _methods_ inside your current working directory (_process.cwd()_), but you can use _path_ to specify a different directory to scan for methods.\n\n- _prefix_\n\n  By default the loaded methods will be available at `server.methods.\u003cmethodName\u003e`. But you can specify a _prefix_ and the plugin will make the functions available at `server.methods.\u003cprefix\u003e.\u003cmethodName\u003e`.\n\n- _verbose_\n\n  When true, will print out information about each method as it is loaded. Default is false.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fhapi-method-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirstandthird%2Fhapi-method-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fhapi-method-loader/lists"}