github.com/micro/go-micro/examples@v0.0.0-20210105173217-bf4ab679e18b/greeter/cli/ruby/sidecar_client.rb (about)

     1  require 'net/http'
     2  require 'json'
     3  
     4  # Sidecar Client example in ruby
     5  #
     6  # This speaks to the service go.micro.srv.greeter
     7  # via the sidecar application HTTP interface
     8  
     9  uri = URI("http://localhost:8081/rpc")
    10  
    11  req = {
    12    "service" => "ruby.micro.srv.greeter",
    13    "method"  => "Say.Hello",
    14    "request" => {"name" => "John"}
    15  }
    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  puts JSON.parse(http.request(request).body)