{"id":19543617,"url":"https://github.com/nodecloud/nodecloud-brakes","last_synced_at":"2025-10-15T05:54:50.450Z","repository":{"id":65463290,"uuid":"89146190","full_name":"nodecloud/nodecloud-brakes","owner":"nodecloud","description":"A circuit client by brakes.","archived":false,"fork":false,"pushed_at":"2017-07-21T06:00:33.000Z","size":39,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-16T10:30:55.348Z","etag":null,"topics":["brake","circuit","node-circuit"],"latest_commit_sha":null,"homepage":"","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/nodecloud.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":"2017-04-23T14:04:22.000Z","updated_at":"2017-07-21T05:51:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"c31a62bf-f234-4c98-b2d8-dc52bd9822da","html_url":"https://github.com/nodecloud/nodecloud-brakes","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.1071428571428571,"last_synced_commit":"56605d7f3299a3fccda2835acec4e518a190f5ec"},"previous_names":["node-cloud/cloud-client"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecloud%2Fnodecloud-brakes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecloud%2Fnodecloud-brakes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecloud%2Fnodecloud-brakes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecloud%2Fnodecloud-brakes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodecloud","download_url":"https://codeload.github.com/nodecloud/nodecloud-brakes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240798582,"owners_count":19859391,"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":["brake","circuit","node-circuit"],"created_at":"2024-11-11T03:19:58.977Z","updated_at":"2025-10-15T05:54:45.404Z","avatar_url":"https://github.com/nodecloud.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NodeCloud-Brakes\n\n## Usage\n\n### UserClient\n``` javascript\nimport BrakeClient from 'nodecloud-brakes';\nimport rp from 'request-promise';\n\nconst SERVICE_NAME = 'user-service';\nconst brake = new BrakeClient(SERVICE_NAME);\n\n//set health check.\nbrake.healthCheck(() =\u003e {\n  return rp({\n      method: 'get',\n      url: `/health`,\n      headers: {\n          'Content-Type': 'application/json'\n      }\n  });\n});\n\nbrake.on('circuitOpen', () =\u003e {\n    logger.warn(`The service: ${SERVICE_NAME}'s circuit is opened.`);\n});\n\nbrake.on('circuitClosed', () =\u003e {\n    logger.info(`The service: ${SERVICE_NAME}'s circuit is closed.`);\n});\n\nbrake.fallback(err =\u003e {\n    throw new Error('Cannot invoke downstream service. please try again soon.', err);\n});\n\nexport function getUser(userId) {\n    const request = {\n        method: 'get',\n        url: `/v1/users/:userId`,\n        params: {userId: userId},\n        headers: {\n            'Content-Type': 'application/json'\n        }\n    };\n    return brake.circuit({send: rp}).send(request);\n}\n```\n\nYou can use brake client to invoke resource api. The example is\n\n``` javascript\nimport * as userClient from './UserClient';\n\nuserClient.getUser(1).then(user =\u003e {\n    console.log(user);\n})\n```\n\n## API\n\n### new BrakeClient(serviceName, options)\n\n##### serviceName\n\nThe service name.\n\n##### options\n\nThe options param is the same as [brakes](https://github.com/node-cloud/brakes).\nWe extend it, and support request handlers\n* options.handler.preHandle(request)\n* options.handler.postHandle(err, response)\n* options.handler.postCircuit(response);\n\n### brake.healthCheck(callback)\n\nSet a callback, when the circuit is open, the callback will be used for checking the service's health status, if the status is ok, the circuit will close.\n\n### brake.on(eventName, callback)\n\nSee [brakes](https://github.com/node-cloud/brakes) for detail.\n\n### brake.isOpen()\n\nReturn the circuit's status.\n\n### brake.circuit(client, fallback, options) : {send(request)}\n\n* client:   (required) an object implement send function.\n* fallback: (optional) fallback function.\n* options   (optional) the same as [brakes](https://github.com/node-cloud/brakes).\n\n### brake.fallback(callback)\n\n* fallback: (optional) the global fallback function.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodecloud%2Fnodecloud-brakes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodecloud%2Fnodecloud-brakes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodecloud%2Fnodecloud-brakes/lists"}