github.com/micro/go-micro/examples@v0.0.0-20210105173217-bf4ab679e18b/greeter/cli/ruby/rpc_client.rb (about) 1 require 'net/http' 2 require 'json-rpc-objects/request' 3 require 'json-rpc-objects/response' 4 5 # RPC Client example in ruby 6 # 7 # This speaks directly to the service go.micro.srv.greeter 8 9 # set the host to the running go.micro.srv.greeter service 10 uri = URI("http://localhost:8080") 11 method = "Say.Hello" 12 request = {:name => "John"} 13 14 # create request 15 req = JsonRpcObjects::Request::create(method, [request], :id => 1) 16 17 # do request 18 http = Net::HTTP.new(uri.host, uri.port) 19 request = Net::HTTP::Post.new(uri.request_uri) 20 request.content_type = 'application/json' 21 request.body = req.to_json 22 23 # parse response 24 puts JsonRpcObjects::Response::parse(http.request(request).body).result["msg"]