Twirp HelloWorld Example
April 30, 2025 ยท View on GitHub
Run the example
To run the example, first make sure you are in the /example folder:
cd example
Install gems:
gem install bundler
bundle install
Start the hello_world server:
bundle exec ruby hello_world_server.rb
Now you can send curl requests from another terminal window:
curl --request POST \
--url http://localhost:8080/twirp/example.hello_world.HelloWorld/Hello \
--header 'Content-Type: application/json; strict=true' \
--data '{"name": "World"}'
To send requests from Ruby code, run the hello_world client example:
bundle exec ruby hello_world_client.rb
Run code generation
Try to add a new field in ./hello_world/service.proto, then run the generator code and see if the new field was properly added in the generated files.
Make sure you have the protobuf compiler (version 3+).
MacOS:
brew install protobuf
Install the twirp plugin with go:
mkdir -p $GOPATH/src/github.com/arthurnn
ln -s ~/src/twirp-ruby $GOPATH/src/github.com/arthurnn/twirp-ruby
go install github.com/arthurnn/twirp-ruby/protoc-gen-twirp_ruby
From the /example folder, run the generator command:
protoc --proto_path=. ./hello_world/service.proto --ruby_out=. --twirp_ruby_out=.