{"id":13411360,"url":"https://github.com/jkyberneees/hydra-plugin-http","last_synced_at":"2025-03-01T02:21:42.126Z","repository":{"id":82947306,"uuid":"89146335","full_name":"jkyberneees/hydra-plugin-http","owner":"jkyberneees","description":"Hydra plugin that adds traditional HTTP requests, routing and proxy capabilities to your hydra micro-services.","archived":false,"fork":false,"pushed_at":"2019-12-30T10:25:32.000Z","size":107,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-11T18:09:24.010Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/jkyberneees.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-23T14:06:14.000Z","updated_at":"2019-12-30T10:25:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"32ea49e7-c123-4c6d-897c-ea78c94a7ab7","html_url":"https://github.com/jkyberneees/hydra-plugin-http","commit_stats":{"total_commits":54,"total_committers":2,"mean_commits":27.0,"dds":"0.14814814814814814","last_synced_commit":"000c1d623a92fd49e958112a07dd38c4513b655a"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jkyberneees%2Fhydra-plugin-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jkyberneees%2Fhydra-plugin-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jkyberneees%2Fhydra-plugin-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jkyberneees%2Fhydra-plugin-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jkyberneees","download_url":"https://codeload.github.com/jkyberneees/hydra-plugin-http/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241305745,"owners_count":19941198,"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":[],"created_at":"2024-07-30T20:01:13.141Z","updated_at":"2025-03-01T02:21:42.121Z","avatar_url":"https://github.com/jkyberneees.png","language":"JavaScript","funding_links":[],"categories":["Web Development"],"sub_categories":["Javascript"],"readme":"# hydra-plugin-http\nHydra plugin that enables traditional HTTP requests, routing and proxy capabilities to your micro-service infrastructure based on [hydra](https://www.hydramicroservice.com/).\n\n\u003e v1.x+ uses `fast-proxy` **(17791.10 reqs/sec)** instead of `http-proxy` *(408.97 reqs/sec)* \n\n# Usage\n## Install Dependencies\n```bash\nnpm i hydra-plugin-http --save\n```\n\u003e This plugin requires hydra version \u003e1.2.10\n## Register the plugin\n```js\nconst hydra = require('hydra');\nconst HydraHttpPlugin = require('hydra-plugin-http').HydraHttpPlugin;\nhydra.use(new HydraHttpPlugin());\n\n// ...\nawait hydra.init({\n    hydra: {\n        'serviceName': 'your-hydra-service-name',\n        'serviceDescription': 'Just another hydra service...',\n        'serviceIP': '127.0.0.1',\n        'servicePort': 0,\n        'serviceType': 'native',\n        'serviceVersion': '1.0.0',\n        'redis': {\n            'host': '127.0.0.1',\n            'port': 6379,\n            'db': 15\n        },\n        'plugins': {\n            'hydra-plugin-http': { // the plugin can be configured in this point or using the constructor\n                'lb': {},\n                'proxy': {}\n            }\n        }\n    }\n});\nawait hydra.registerService();\n```\n## Use it ;)\n\nMaking HTTP requests to internal/external micro-services using [axios](https://www.npmjs.com/package/axios):\n```js\n// GET request targeting an internal endpoint in the cluster\nlet res = await hydra.http.request('/v1/email/config');\n\n// POST request targeting an internal endpoint in the cluster\nres = await hydra.http.request.post('/v1/email/send', {\n    to: 'account@email.com'\n    // ...\n});\n\n// GET request targeting an external endpoint\nres = await hydra.http.request('https://www.google.de/?q=hydra+microservices');\n```\n\u003e The **request** object is literally an instance of *axios*, with automatic URL resolving for internal micro-services. As simple as it can be ;)  \n\u003e Any URL with the schema */:servicename/:route* or */:route*, will be automatically translated into a valid URL in the micro-service cluster. \n\n### Capturing request events for pre/post processing\n```js\nhydra.on('http-plugin-request', e =\u003e {\n    // example of how to set the Authorization header on internal calls\n    if ('request' == e.name \u0026\u0026 'info' == e.name.level \u0026\u0026 e.data.targetHydraCluster) {\n        e.data.headers['Authorization'] = `Bearer ${getJwtToken()}`;\n    }\n});\n```\n\n## Demos\nDemos available into [demos folder](demos) on the git repository: https://github.com/jkyberneees/hydra-plugin-http\n\n# Next topics\n- [The Service Load Balancer](docs/lb.md)\n- [The HTTP Proxy/Router](docs/proxy.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjkyberneees%2Fhydra-plugin-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjkyberneees%2Fhydra-plugin-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjkyberneees%2Fhydra-plugin-http/lists"}