{"id":15684234,"url":"https://github.com/feugy/mini-service","last_synced_at":"2025-05-07T15:21:47.473Z","repository":{"id":57297735,"uuid":"62563614","full_name":"feugy/mini-service","owner":"feugy","description":"Micro services done simply. Choose to run them locally or remotely","archived":false,"fork":false,"pushed_at":"2018-11-25T16:41:19.000Z","size":543,"stargazers_count":10,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-30T04:05:41.658Z","etag":null,"topics":["hapijs","microservices","nodejs"],"latest_commit_sha":null,"homepage":"https://feugy.github.io/mini-service/","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/feugy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-07-04T13:18:25.000Z","updated_at":"2018-04-22T20:13:55.000Z","dependencies_parsed_at":"2022-09-01T08:41:31.851Z","dependency_job_id":null,"html_url":"https://github.com/feugy/mini-service","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feugy%2Fmini-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feugy%2Fmini-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feugy%2Fmini-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feugy%2Fmini-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/feugy","download_url":"https://codeload.github.com/feugy/mini-service/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252902730,"owners_count":21822292,"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":["hapijs","microservices","nodejs"],"created_at":"2024-10-03T17:13:17.369Z","updated_at":"2025-05-07T15:21:47.454Z","avatar_url":"https://github.com/feugy.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Mini-service\n\nSimplistic µService library\n\n[![npm package][npm-badge]][npm-url]\n[![NSP Status][nsp-badge]][nsp-url]\n[![dependencies][david-badge]][david-url]\n[![build][travis-badge]][travis-url]\n[![coverage][coveralls-badge]][coveralls-url]\n[![License: MIT][license-badge]][license-url]\n\n- [API Reference][api-reference-url]\n- [Frequently asked questions][faq]\n- [Examples][examples]\n\n## Introduction\n\nThe goal of mini-service is to give the minimal structure to implement a µService, that can be invoked locally or remotely.\n\nIts principles are the following:\n- very easy to add new service api endpoints\n- easy to use client interface, same usage both locally and remotely\n- hide deployment details and provide simple-yet-working solution\n- promises based (and thus, async/await compatible)\n\nmini-service uses the latest ES6 features, so it requires node 6+\n\n\n## Example\n\nHere is a simple calculator service definition, that exposes functions to add and subtract numbers.\n\n`calc-service.js`\n```js\nmodule.exports = {\n  name: 'calc-service',\n  version: '1.0.0',\n  init: () =\u003e {\n    // each exposed APIs could also return a promise/be async\n    add: (a, b) =\u003e a + b,\n    subtract: (a, b) =\u003e a - b\n  }\n}\n```\n\nIf you want to use it locally in a different file:\nrequire the service definition, and create a [mini-client][mini-client-url] with it\n\n`caller-local.js`\n```js\nconst {getClient} = require('mini-service')\nconst calcService = require('./calc-service')\n\nconst calc = getClient(calcService)\n```\n\nThen, init it (it's an async operation) and invoke any exposed API you need:\n\n`caller-local.js`\n```js\nawait calc.init()\nconst sum = await calc.add(10, 5)\nconsole.log(`Result is: ${sum}`)\n```\n\nNow let's imagine you need to deploy your calculator service in a standalone Http server, and invoke it from a remote server.\nTo turn your local service into a real server, expose your service definition with mini-service's `startServer()`:\n\n`calc-service.js`\n```js\nconst {startServer} = require('mini-service')\n\nmodule.exports = {...} // same service definition as above\n// starts Http server\nstartServer(module.exports)\n```\nA server is now listening on port 3000.\n\nAnd to use it from a remote caller, creates a mini-client giving the proper url:\n\n`caller-remote.js`\n```js\nconst getClient = require('mini-client') // or: const {getClient} = require('mini-service')\n\nconst calc = getClient({\n  remote: 'http://localhost:3000'\n})\n```\nPlease note that you **don't need to require the service definition anymore**.\n\nUsage is exactly the same as previously.\n\n`caller-remote.js`\n```js\nawait calc.init() // no-op, can be skipped\nconst sum = await calc.add(10, 5)\nconsole.log(`Result is: ${sum}`)\n```\n\n\n## Acknowledgements\n\nThis project was kindly sponsored by [nearForm][nearform].\n\n\n## License\n\nCopyright [Damien Simonin Feugas][feugy] and other contributors, licensed under [MIT](./LICENSE).\n\n\n## Changelog \u0026 migration guide\n\nAll changes to this project are be documented [here][changelog]. \n\nThe format is based on [Keep a Changelog][keep-a-changelog] and this project adheres to [Semantic Versioning][semver].\n\n### 3.x to 4.x migration\n\nVersion 4 is using async/await, which requires node@8+.\n\nThe only breaking change is on `startServer()`:\n- previously it threw synrchonous errors while validating configuration.\n- now all errors are thrown asynchronously\n\n\n#### 2.x to 3.x migration\n\nGroups are now used as sub-objects of mini-client.\n\nGiven a service exposing:\n- api `ping` without group *(or if group has same name as overall service)*\n- group `a` with apis `ping` \u0026 `pong`\n- group `b` with api `ping`\n\nthe final Mini-client will be:\n```js\nclient = {\n  ping(),\n  a: {\n    ping(),\n    pong()\n  },\n  b: {\n    ping()\n  }\n}\n```\n\n\n### 1.x to 2.x migration\n\nLocal services, as remote services, **must** have `name` and `version` options defined\n\nWhen loading services, the `services` property was renamed to `groups`, and `serviceOpts` is now `groupOpts`:\n\n```js\nconst {startServer} = require('mini-service')\n\nstartServer({\n  groups: [ // was services previously\n    require('../serviceA'),\n    require('../serviceB'),\n    require('../serviceC')\n  ],\n  groupOpts: { // was serviceOpts previously\n    serviceA: {},\n    serviceB: {},\n    serviceC: {}\n  }\n})\n```\n\n[nearform]: http://nearform.com\n[feugy]: https://github.com/feugy\n[david-badge]: https://img.shields.io/david/feugy/mini-service.svg\n[david-url]: https://david-dm.org/feugy/mini-service\n[npm-badge]: https://img.shields.io/npm/v/mini-service.svg\n[npm-url]: https://npmjs.org/package/mini-service\n[travis-badge]: https://api.travis-ci.org/feugy/mini-service.svg\n[travis-url]: https://travis-ci.org/feugy/mini-service\n[coveralls-badge]: https://img.shields.io/coveralls/feugy/mini-service/master.svg\n[coveralls-url]: https://coveralls.io/r/feugy/mini-service?branch=master\n[api-reference-url]: https://feugy.github.io/mini-service/?api\n[faq]: https://feugy.github.io/mini-service/?content=faq\n[examples]: https://github.com/feugy/mini-service/tree/master/examples\n[mini-client]: https://feugy.github.io/mini-client/\n[license-badge]: https://img.shields.io/badge/License-MIT-green.svg\n[license-url]: https://github.com/feugy/mini-service/blob/master/LICENSE\n[nsp-badge]: https://nodesecurity.io/orgs/perso/projects/6bc9b474-6f9e-4db0-a4d3-c3bf5443a63a/badge\n[nsp-url]: https://nodesecurity.io/orgs/perso/projects/6bc9b474-6f9e-4db0-a4d3-c3bf5443a63a\n[changelog]: https://feugy.github.io/mini-service/?content=changelog\n[keep-a-changelog]: https://keepachangelog.com\n[semver]: https://semver.org","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeugy%2Fmini-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeugy%2Fmini-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeugy%2Fmini-service/lists"}