Skip to content

Instantly share code, notes, and snippets.

@lega911
Last active December 17, 2019 21:59
Show Gist options
  • Save lega911/b8deeb5ce0aad6b99aa582434b02cf0d to your computer and use it in GitHub Desktop.
Save lega911/b8deeb5ce0aad6b99aa582434b02cf0d to your computer and use it in GitHub Desktop.
RPC example
# 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