Skip to content
Snippets Groups Projects
Commit b44fae11 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Accept body data in PUT

parent 256dfc0d
No related branches found
No related tags found
No related merge requests found
......@@ -13,12 +13,13 @@ HOST = '127.0.0.1'
PORT = 6221
uri = 'http://{}:{}/'.format(HOST, PORT)
def hit_endpoint(method, endpoint, params=None):
def hit_endpoint(method, endpoint, params=None, body=None):
"""
Python 2.7 implementation of HTTP client
:param method: (str) either 'GET' or 'PUT'
:param endpoint: (str) endpoint of HTTP request
:param params: (dict) of parameters required by client request
:param params: (dict) of parameters that are embedded in client request URL
:param body: (dict) of parameters that JSON-encoded and attached as payload in request
:return: (dict) of response status and content, formatted as dict if request is successful
"""
connection = httplib.HTTPConnection(HOST, PORT)
......@@ -28,7 +29,7 @@ def hit_endpoint(method, endpoint, params=None):
url = endpoint + '?' + urllib.urlencode(params)
else:
url = endpoint
connection.request(method, url)
connection.request(method, url, body=json.dumps(body))
resp = connection.getresponse()
resp_str = resp.read()
try:
......
from adapter import hit_endpoint, verify_server
import os
import sys
for sp in ['model_server/model_server/clients', 'trec_adaptive_feedback/trec_adaptive_feedback/clients']:
sys.path.append(os.path.join(os.path.expanduser('~'), sp))
from imagej.adapter import hit_endpoint, verify_server
if __name__ == '__main__':
print(verify_server())
print(verify_server(popup=False))
data = {'par1': 'hello', 'par2': ['ab', 'cd']}
resp = hit_endpoint('PUT', '/', params=None)
resp = hit_endpoint('PUT', '/bounce_back', params=None)
print(resp)
assert resp['status'] == 200
print('Finished')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment