Last active
December 17, 2019 21:59
-
-
Save lega911/b8deeb5ce0aad6b99aa582434b02cf0d to your computer and use it in GitHub Desktop.
RPC example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# client.py | |
import requests | |
print(requests.post('http://127.0.0.1:8001/test/command', json={'id': 1, 'params': 'Hello'}).json()) | |
# worker.py | |
import requests | |
while True: | |
req = requests.post('http://127.0.0.1:8001/test/command', headers={'Type': 'get'}).json() | |
response = { | |
'id': req['id'], | |
'result': req['params'] + ' world!' | |
} | |
requests.post('http://127.0.0.1:8001/', json=response, headers={'Type': 'result'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment