namtx / gruf-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

README

Running up project

foreman start -f Procfile.dev

How to test out

  • Create product
curl --request POST \
  --url http://localhost:3000/clients \
  --header 'content-type: application/json' \
  --data '{
	"name": "iPhone 11",
	"price": 4444
}'
  • Get products
curl --request GET \
  --url http://localhost:3000/clients
  • Get product
curl --request GET \
  --url http://localhost:3000/clients/1

Build your own one

  • Create a normal rails project by:
rails new <project_name>
  • Add proto file

In my case it is app/proto/Products.proto

  • Generate gRPC services code
./bin/generate_protos.sh
  • Create gRPC Server controller Checkout app/rpc/products_controller.rb

  • How to run up gRPC server?

bundle exec gruf --host=localhost:9003

and your gRPC server will run on port 9003

  • Implement Client controller Checkout app/controllers/clients_controller.rb

  • Run up client as normal rails application

rails s

Your client app will run on port 3000, and we can send a normal HTTP request to this port

About


Languages

Language:Ruby 99.0%Language:HTML 0.8%Language:Shell 0.3%