{"id":18728758,"url":"https://github.com/rubyonworld/grpc-web-ruby","last_synced_at":"2026-04-13T01:38:20.226Z","repository":{"id":174007924,"uuid":"540252394","full_name":"RubyOnWorld/grpc-web-ruby","owner":"RubyOnWorld","description":"Host gRPC-Web endpoints for Ruby gRPC services in a Rails or Rack app (over HTTP/1). Client included.","archived":false,"fork":false,"pushed_at":"2022-09-23T02:41:42.000Z","size":399,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-19T20:32:47.209Z","etag":null,"topics":["grpc","rack","rails","ruby","web"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/RubyOnWorld.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2022-09-23T02:41:21.000Z","updated_at":"2022-09-27T21:06:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"e98823cc-4318-4c5d-b5e0-67d5a624c2b5","html_url":"https://github.com/RubyOnWorld/grpc-web-ruby","commit_stats":null,"previous_names":["rubyonworld/grpc-web-ruby"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/RubyOnWorld/grpc-web-ruby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fgrpc-web-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fgrpc-web-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fgrpc-web-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fgrpc-web-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RubyOnWorld","download_url":"https://codeload.github.com/RubyOnWorld/grpc-web-ruby/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fgrpc-web-ruby/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31736723,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-12T22:19:12.206Z","status":"ssl_error","status_checked_at":"2026-04-12T22:18:33.088Z","response_time":58,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["grpc","rack","rails","ruby","web"],"created_at":"2024-11-07T14:24:16.240Z","updated_at":"2026-04-13T01:38:20.191Z","avatar_url":"https://github.com/RubyOnWorld.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gRPC-Web Ruby\n\n[![Gusto](https://circleci.com/gh/Gusto/grpc-web-ruby/tree/master.svg?style=shield\u0026circle-token=062a6c1a39b142a123eefe766baf90c51f8dd699)](https://circleci.com/gh/Gusto/grpc-web-ruby/tree/master)\n\n## Background\nHost gRPC-Web endpoints for Ruby gRPC services in a Rails or Rack app (over HTTP/1). Client included.\n\n### gRPC vs gRPC-Web\n\ngRPC-Web is a variation of the gRPC protocol adapted to function over an HTTP/1 connection. This allows gRPC services to be accessed by web browser clients and using infrastructure that does not support end-to-end HTTP/2 load balancing like AWS ELBs and ALBs. ALBs only support HTTP/2 client -\u003e LB not LB -\u003e service.\n\n### Use Cases for gRPC-Web\n\n1. **Client -\u003e Server:** Access typed gRPC + Protobuf APIs from javascript in the browser.\n2. **Service \u003c-\u003e Service:** Communicate between services using typed gRPC + Protobuf APIs over existing HTTP/1 infrastructure and load balancing solutions.\n\n### More Information\n[gRPC-Web Introductory Blog Post](https://grpc.io/blog/grpc-web-ga/)\n\n[gRPC-Web Protocol (with comparison against gRPC)](https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-WEB.md)\n\n## Compatibility\n\n#### Supported Content Types\n1. application/grpc-web\n1. application/grpc-web+proto\n1. application/grpc-web+json\n1. application/grpc-web-text (base64 encoded)\n1. application/grpc-web-text+proto (base64 encoded)\n\n#### Integration testing\n\ngRPC-Web Ruby includes integration tests between the following implementations of gRPC-Web:\n1. Ruby Client with Ruby Server\n2. Javascript Client with Ruby Server\n3. Ruby Client with Envoy Proxy Server\n\n## Getting Started\nAdd the gem to your Gemfile:\n```ruby\ngem 'grpc-web'\n```\n\n### Implement a gRPC Service in Ruby\nBuild a service using the standard [Ruby gRPC library](https://github.com/grpc/grpc/tree/master/src/ruby) or use any existing ruby gRPC service. For a more complete introduction to gRPC in Ruby checkout the [gRPC Ruby Quickstart](https://grpc.io/docs/quickstart/ruby/).\n\n#### Define the service API using Protobuf\n```protobuf\n# hello.proto\nsyntax = \"proto3\";\n\nmessage HelloRequest {\n  string name = 1;\n}\n\nmessage HelloResponse {\n  string message = 1;\n}\n\nservice HelloService {\n  rpc SayHello(HelloRequest) returns (HelloResponse);\n}\n\n```\n\n#### Generate ruby code\n```ruby\n# hello_pb.rb\nrequire 'google/protobuf'\n\nGoogle::Protobuf::DescriptorPool.generated_pool.build do\n  add_file(\"hello.proto\", :syntax =\u003e :proto3) do\n    add_message \"HelloRequest\" do\n      optional :name, :string, 1\n    end\n    add_message \"HelloResponse\" do\n      optional :message, :string, 1\n    end\n  end\nend\n\nHelloRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup(\"HelloRequest\").msgclass\nHelloResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup(\"HelloResponse\").msgclass\n```\n\n```ruby\n# hello_services_pb.rb\nrequire 'grpc'\nrequire 'hello_pb'\n\nmodule HelloService\n  class Service\n\n    include GRPC::GenericService\n\n    self.marshal_class_method = :encode\n    self.unmarshal_class_method = :decode\n    self.service_name = 'HelloService'\n\n    rpc :SayHello, HelloRequest, HelloResponse\n  end\n\n  Stub = Service.rpc_stub_class\nend\n```\n\n#### Implement the service\n\n```ruby\n# example_hello_service.rb\nrequire 'hello_services_pb'\n\nclass ExampleHelloService \u003c HelloService::Service\n  def say_hello(request, _call = nil)\n    return HelloResponse.new(message: \"Hello #{request.name}\")\n  end\nend\n```\n\n### Run a gRPC-Web Server\nYou can run a gRPC-Web server using any Rack compliant HTTP server such as WEBrick, Unicorn, or Puma. You can also mount gRPC-Web endpoints alongside a Rails, Sinatra, or other Rack application.\n\n#### Running with WEBrick\n```ruby\n# example_grpc_web_server.rb\nrequire 'grpc_web'\nrequire 'example_hello_service'\nrequire 'rack/handler'\n\nGRPCWeb.handle(ExampleHelloService)\nRack::Handler::WEBrick.run GRPCWeb.rack_app\n```\n\n#### Running with Basic Auth\nSince you can run a gRPC-Web server using any Rack compliant app, you can accordingly support basic authentication for the server as well.\n\n```ruby\n# example_grpc_web_server.rb\nrequire 'grpc_web'\nrequire 'example_hello_service'\nrequire 'rack/handler'\n\nGRPCWeb.rack_app.use Rack::Auth::Basic do |username, password|\n  [user, password] == [\"foobar\", \"verysecret\"]\nend\n\nGRPCWeb.handle(ExampleHelloService)\n\nRack::Handler::WEBrick.run GRPCWeb.rack_app\n```\n\nNow you can point your client to a Basic Auth comformant URL for this rack service. Example: `http://foobar:verysecret@localhost:3000/grpc`. Or via authentication headers, which ever is best suited by the client.\n\n## Configuring Services\n\nLike the standard gRPC **RpcServer** class, `GRPCWeb.handle` accepts either an instance of a service or a service class. gRPC-Web also supports a block syntax for `.handle` that enables lazy loading of service classes.\n\n#### Instance of a service\n```ruby\nGRPCWeb.handle(ExampleHelloService.new('initializer argument'))\n```\n\n#### Service class\nWhen a service class is provided a new instance will be created for each request using `.new`.\n\n```ruby\nGRPCWeb.handle(ExampleHelloService)\n```\n\n#### Lazy initialization block\nThe argument to `.handle` is the service interface class (generated from proto) when using a lazy init block.\n\n```ruby\nGRPCWeb.handle(HelloService::Service) do\n  require 'example_hello_service'\n  ExampleHelloService.new\nend\n```\n\n## Integration with Rails\ngRPC-Web Ruby is designed to integrate easily with an existing Ruby on Rails application.\n\n#### Mount gRPC-Web in the Rails route file\n```ruby\n# config/routes.rb\nrequire 'grpc_web'\n\nRails.application.routes.draw do\n  mount GRPCWeb.rack_app =\u003e '/grpc'\n  ...\nend\n```\n\n#### Configure services in an initializer\n```ruby\n# config/initializers/grpc_web.rb\nrequire 'hello_services_pb'\n\nGRPCWeb.handle(HelloService::Service) do\n  require_dependency 'example_hello_service'\n  ExampleHelloService.new\nend\n```\n\n## Using the Ruby Client\nThe gRPC-Web Ruby client is tested to be compatible with both the gRPC-Web Ruby server and the Envoy gRPC-Web proxy.\n\n#### Creating a client\n```ruby\nrequire 'grpc_web/client'\nrequire 'hello_services_pb'\n\n$client = GRPCWeb::Client.new(\"http://localhost:3000/grpc\", HelloService::Service)\n```\n\n#### Calling a method\n```ruby\n$client.say_hello(name: 'James')\n# =\u003e \u003cHelloResponse: message: \"Hello James\"\u003e\n```\n\nYou can also pass custom headers:\n```ruby\n$client.say_hello({name: 'James'}, {metadata: {'custom-header' =\u003e 'Hello'}})\n```\n\n#### Using Basic Auth\ngRPC-Web Ruby client supports Basic Auth out of the box. You can pass in a Basic Auth comformant URL and gRPC-Web Ruby client will take care of the rest when interacting with the server.\n\n```ruby\n$client = GRPCWeb::Client.new(\"http://foobar:verysecret@localhost:3000/grpc\", HelloService::Service)\n```\n\n### Error Handling\n\nThe gRPC-Web Ruby client and server libraries support the propagation of exceptions using the standard `grpc-status` and `grpc-message` trailers.\n\ngRPC-Web uses the [standard error classes from the core grpc library](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/errors.rb). Any instance or subclass of `GRPC::BadStatus` thrown in a service implementation will propoagate across the wire and be raised as an exception of the same class on the client side. Any other `Error` will be treated as a `GRPC::Unknown`.\n\n### Configuring an on_error callback\n```ruby\n# config/initializers/grpc_web.rb\nGRPCWeb.on_error do |ex, service, service_method|\n  ErrorNotifier.notify(ex, metadata: { service: service.class.service_name, method: service_method})\nend\n```\n\n## Additional Notes\n\n### CORS Middleware (for browser clients)\n\nWeb Browser clients will only allow HTTP requests to be made to your gRPC-Web API if CORS headers are correctly configured or the request is sameorigin (the gRPC-Web endpoints are hosted on the same domain that served the javascript code). You will need to use a library like [cyu/rack-cors](https://github.com/cyu/rack-cors) to manage CORS if you want to support browsers.\n\n\n## Contributing\n\nSee the [developer's guide](CONTRIBUTING.md)\n\n## Useful links\n\ngRPC-Web Repo (protoc generator, js-client, proxy server)\nhttps://github.com/grpc/grpc-web\n\nImprobable Eng gRPC Repo (js-client w/ TypeScript + NodeJS support, golang server)\nhttps://github.com/improbable-eng/grpc-web\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Fgrpc-web-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubyonworld%2Fgrpc-web-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Fgrpc-web-ruby/lists"}