{"id":22608900,"url":"https://github.com/bitfinexcom/grenache-ruby-http","last_synced_at":"2025-08-21T10:31:44.036Z","repository":{"id":56875287,"uuid":"63182759","full_name":"bitfinexcom/grenache-ruby-http","owner":"bitfinexcom","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-05T06:37:01.000Z","size":121,"stargazers_count":6,"open_issues_count":2,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-08T04:07:55.014Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitfinexcom.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":"2016-07-12T18:28:17.000Z","updated_at":"2024-09-05T06:37:06.000Z","dependencies_parsed_at":"2022-08-20T10:11:11.841Z","dependency_job_id":null,"html_url":"https://github.com/bitfinexcom/grenache-ruby-http","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/bitfinexcom%2Fgrenache-ruby-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fgrenache-ruby-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fgrenache-ruby-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fgrenache-ruby-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitfinexcom","download_url":"https://codeload.github.com/bitfinexcom/grenache-ruby-http/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230507051,"owners_count":18236944,"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-12-08T15:10:02.109Z","updated_at":"2024-12-19T22:08:33.270Z","avatar_url":"https://github.com/bitfinexcom.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# grenache-ruby-http\n\n\u003cimg src=\"logo.png\" width=\"15%\" /\u003e\n\nGrenache is a micro-framework for connecting microservices. Its simple and optimized for performance.\n\nInternally, Grenache uses Distributed Hash Tables (DHT, known from Bittorrent) for Peer to Peer connections. You can find more details how Grenche internally works at the [Main Project Homepage](https://github.com/bitfinexcom/grenache)\n\n - [Setup](#setup)\n - [Examples](#examples)\n - [API](#api)\n\n## Setup\n\n### Install\n```\ngem install grenache-ruby-http\n```\n\n### Other Requirements\n\nInstall `Grenache Grape`: https://github.com/bitfinexcom/grenache-grape:\n\n```bash\nnpm i -g grenache-grape\n```\n\n```\n// Start 2 Grapes\ngrape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'\ngrape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'\n```\n\n## Examples\n\n#### RPC Server / Client\n\nThis RPC Server example announces a service called `rpc_test`\non the overlay network. When a request from a client is received,\nit replies with `world`. It receives the payload `hello` from the\nclient.\n\nThe client sends `hello` and receives `world` from the server.\n\nInternally the DHT is asked for the IP of the server and then the\nrequest is done as Peer-to-Peer request via websockets.\n\n**Grape:**\n\n```bash\ngrape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'\ngrape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'\n```\n\n**Server:**\n\n```rb\nrequire \"grenache-ruby-http\"\n\nEM.run do\n  Signal.trap(\"INT\")  { EventMachine.stop }\n  Signal.trap(\"TERM\") { EventMachine.stop }\n\n  c = Grenache::Http.new(grape_address: \"http://127.0.0.1:40001/\")\n  port = 5001\n\n  c.listen(\"test_service\", port) do |req|\n      \"hello #{req.payload}\"\n  end\nend\n```\n\n**Client:**\n\n```rb\nrequire \"grenache-ruby-http\"\n\nc = Grenache::Http.new(grape_address: \"http://127.0.0.1:40001/\")\n\nresp, err = c.request(\"test_service\", \"world\")\n\nputs \"response: #{resp}\"\n\n```\n\n[Code Server](https://github.com/bitfinexcom/grenache-ruby-http/blob/master/examples/worker.rb)\n[Code Client](https://github.com/bitfinexcom/grenache-ruby-http/blob/master/examples/client.rb)\n\n## API\n\n### Class: Grenache::Http\n\n### Grenache::Http.new(options)\n  - `options`\n    - `:grape_address` \u0026lt;String\u0026gt;\n    - `:timeout` \u0026lt;Number\u0026gt;\n\n    - `:auto_announce_interval` \u0026lt;Number\u0026gt;\n    - `:auto_announce` \u0026lt;Boolean\u0026gt;\n    - `:service_timeout` \u0026lt;Number\u0026gt;\n    - `:service_host` \u0026lt;String\u0026gt;\n\n    - `:key` \u0026lt;String\u0026gt; SSL: Path to key file\n    - `:cert_pem` \u0026lt;String\u0026gt; SSL: Path to chain file\n    - `:ca` \u0026lt;String\u0026gt; SSL: Path to ca file\n    - `:service_host` \u0026lt;String\u0026gt; SSL: host name, used for worker\n    - `:reject_unauthorized` SSL: Reject unauthorized certs\n    - `:verify_mode` SSL: Verification method, default `Grenache::SSL_VERIFY_PEER`\n\n\n### client.request(name, payload, options)\n  - `name` \u0026lt;String\u0026gt; Name of the service to address\n  - `payload` Payload to send\n  - `options`\n    - `:timeout` Timeout for the request\n\nSends a single request to a RPC server/worker.\n[Example](https://github.com/bitfinexcom/grenache-ruby-http/blob/master/examples/client.rb).\n\n\n### client.put(data, options)\n\n  - `data`\n    - `:v`: \u0026lt;String\u0026gt; value to store\n  - `options`\n    - `:timeout` Timeout for the request\n\nPuts a value into the DHT.\n\n### client.get(hash)\n  - `hash` \u0026lt;String\u0026gt; Hash of the data to receive\n\nRetrieves a stored value from the DHT via a `hash` \u0026lt;String\u0026gt;.\n\n### client.listen(key, port, options)\n  - `name` \u0026lt;String\u0026gt; Name of the service to announce\n  - `port` \u0026lt;Number\u0026gt; Port to listen\n  - `options`\n\nSets up a worker which connects to the DHT.\nListens on the given `port`.\n\n[Example](https://github.com/bitfinexcom/grenache-ruby-http/blob/master/examples/worker.rb).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitfinexcom%2Fgrenache-ruby-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitfinexcom%2Fgrenache-ruby-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitfinexcom%2Fgrenache-ruby-http/lists"}