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:
22
examples/greeter/cli/python/rpc_client.py
Normal file
22
examples/greeter/cli/python/rpc_client.py
Normal file
@ -0,0 +1,22 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
|
||||
def main():
|
||||
url = "http://localhost:4000"
|
||||
headers = {'content-type': 'application/json'}
|
||||
|
||||
# Example echo method
|
||||
payload = {
|
||||
"method": "Say.Hello",
|
||||
"params": [{"name": "John"}],
|
||||
"jsonrpc": "2.0",
|
||||
"id": 0,
|
||||
}
|
||||
response = requests.post(
|
||||
url, data=json.dumps(payload), headers=headers).json()
|
||||
|
||||
print response["result"]
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
21
examples/greeter/cli/python/sidecar_client.py
Normal file
21
examples/greeter/cli/python/sidecar_client.py
Normal file
@ -0,0 +1,21 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
|
||||
def main():
|
||||
url = "http://localhost:8081/rpc"
|
||||
headers = {'content-type': 'application/json'}
|
||||
|
||||
# Example echo method
|
||||
payload = {
|
||||
"service": "go.micro.srv.greeter",
|
||||
"method": "Say.Hello",
|
||||
"request": {"name": "John"},
|
||||
}
|
||||
response = requests.post(
|
||||
url, data=json.dumps(payload), headers=headers).json()
|
||||
|
||||
print response
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user