{"id":20039205,"url":"https://github.com/defra/hapi-api-boilerplate","last_synced_at":"2025-05-05T07:32:30.374Z","repository":{"id":41810770,"uuid":"148623444","full_name":"DEFRA/hapi-api-boilerplate","owner":"DEFRA","description":"hapijs boilerplate api project","archived":false,"fork":false,"pushed_at":"2025-03-24T14:52:46.000Z","size":243,"stargazers_count":5,"open_issues_count":3,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-08T19:08:24.937Z","etag":null,"topics":["government","govuk","hapijs"],"latest_commit_sha":null,"homepage":null,"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/DEFRA.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-13T10:43:15.000Z","updated_at":"2025-03-24T14:24:22.000Z","dependencies_parsed_at":"2022-08-11T18:10:41.922Z","dependency_job_id":null,"html_url":"https://github.com/DEFRA/hapi-api-boilerplate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEFRA%2Fhapi-api-boilerplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEFRA%2Fhapi-api-boilerplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEFRA%2Fhapi-api-boilerplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEFRA%2Fhapi-api-boilerplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DEFRA","download_url":"https://codeload.github.com/DEFRA/hapi-api-boilerplate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252458594,"owners_count":21751068,"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":["government","govuk","hapijs"],"created_at":"2024-11-13T10:36:23.811Z","updated_at":"2025-05-05T07:32:30.368Z","avatar_url":"https://github.com/DEFRA.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# (Enter service name)\n(Description of the service)\n\n# Environment variables\n(Be sure to describe any environment variables here by maintaining a list like this)\n\n| name     | description      | required | default |            valid            | notes |\n|----------|------------------|:--------:|---------|:---------------------------:|-------|\n| NODE_ENV | Node environment |    no    |         | development,test,production |       |\n| PORT     | Port number      |    no    | 3000    |                             |       |\n\n# Prerequisites\n\nNode v8+\n\n\n# (Checklist)\nOnce you clone this repository you'll need to make a few changes before you're ready to start:\n\n- [ ] Add service name and description to the README above\n- [ ] Update the `package.json` with the name, description and any git urls and authors etc.  \n- [ ] Remove the .git folder in the root directory. This will cut the cord to this boilerplate repo.\n- [ ] Update the build status badges for your new project\n\n# Running the application\n\n`$ node index.js`\n\n\n(You can delete the remainder of this readme once you're up and running)\n\n## What is this?\n\nA simple hapi-based enterprise ready API application boilerplate.\nClick here for a similar [web boilerplate hapi project](https://github.com/DEFRA/hapi-web-boilerplate).\n\nBased on:\n\n- [hapijs](https://github.com/hapijs/hapi) - The framework \u0026 core plugins like `joi`, `h2o2` etc.\n- [neostandard](https://github.com/neostandard/neostandard) - Linting\n- [npm-scripts](https://docs.npmjs.com/misc/scripts) - Build tool\n- [pm2](https://github.com/Unitech/pm2) - Process manager\n\n\n## Getting started\n\nClone this repo and run through the checklist above.\n\nCheck the server is running by pointing your browser to `http://localhost:3000`\n\n## Project structure\n\nHere's the default structure for your project files.\n\n* **server**\n  * **plugins**\n  * **routes**\n  * config.js\n  * index.js (Exports a function that creates a server)\n* **test**\n* README.md\n* index.js (startup server)\n\n## Config\n\nThe configuration file for the server is found at `server/config.js`.\nThis is where to put any config and all config should be read from the environment.\nThe final config object should be validated using joi and the application should not start otherwise.\n\nA table of environment variables should be maintained in this README.\n\n## Plugins\n\nhapi has a powerful plugin system and all server code should be loaded in a plugin.\n\nPlugins live in the `server/plugins` directory.\n\n## Logging\n\nThe [@hapi/log](https://github.com/hapijs/log) is included and configured in `server/plugins/logging`\n\n## Routes\n\nIncoming requests are handled by the server via routes. \nEach route describes an HTTP endpoint with a path, method, and other properties.\n\nRoutes are found in the `server/routes` directory and loaded using the `server/plugins/router.js` plugin.\n\nHapi supports registering routes individually or in a batch.\nEach route file can therefore export a single route object or an array of route objects.\n\nA single route looks like this:\n\n```js\n{\n  method: 'GET',\n  path: '/hello-world',\n  options: {\n    handler: (request, h) =\u003e {\n      return 'hello world'\n    }\n  }\n}\n```\n\nThere are lots of [route options](http://hapijs.com/api#route-options), here's the documentation on [hapi routes](http://hapijs.com/tutorials/routing)\n\n## Tasks\n\nBuild tasks are created using simple shell scripts or node.js programs.\nThe default ones are found in the `bin` directory.\n\nThe task runner is simply `npm` using `npm-scripts`.\n\nWe chose to use this for simplicity but there's nothing to stop you adding `gulp`, `grunt` or another task runner if you prefer. \n\nThe predefined tasks are:\n\n- `npm run lint` (Runs the lint task using neostandard)\n- `npm run unit-test` (Runs the `lab` tests in the `/test` folder)\n- `npm test` (Runs the `lint` task then the `unit-tests`)\n\n### Resources\n\nFor more information around using `npm-scripts` as a build tool:\n\n- http://substack.net/task_automation_with_npm_run\n- http://ponyfoo.com/articles/choose-grunt-gulp-or-npm\n- http://blog.keithcirkel.co.uk/why-we-should-stop-using-grunt/\n- http://blog.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/\n\n## Testing\n\n[jest](https://https//jestjs.io/) is used for unit testing.\n\nSee the `/__test__` folder for more information.\n\n## Linting\n\n[neostandard](https://github.com/neostandard/neostandard) is used to lint both the server-side and client-side javascript code.\n\nIt's defined as a build task and can be run using `npm run lint`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefra%2Fhapi-api-boilerplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdefra%2Fhapi-api-boilerplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefra%2Fhapi-api-boilerplate/lists"}