1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-12 22:07:47 +02:00

Add examples

This commit is contained in:
Asim Aslam
2020-12-26 15:17:20 +00:00
parent 273bab5dd7
commit a34c70de0e
320 changed files with 20803 additions and 0 deletions

View File

@ -0,0 +1,24 @@
require 'net/http'
require 'json-rpc-objects/request'
require 'json-rpc-objects/response'
# RPC Client example in ruby
#
# This speaks directly to the service go.micro.srv.greeter
# set the host to the running go.micro.srv.greeter service
uri = URI("http://localhost:8080")
method = "Say.Hello"
request = {:name => "John"}
# create request
req = JsonRpcObjects::Request::create(method, [request], :id => 1)
# do request
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.content_type = 'application/json'
request.body = req.to_json
# parse response
puts JsonRpcObjects::Response::parse(http.request(request).body).result["msg"]