-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequest_handler.py
executable file
·45 lines (34 loc) · 1.4 KB
/
request_handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#########################################################################################################
# @Author: --
# @Description: Request manager -- GET request handler
# @Usage: Used in Client.py as grounding library
#########################################################################################################
import json
import requests
class Configuration:
def __init__(self, ip='localhost', port='3030', datasource='ds'):
self.ip = ip
self.port = port
self.datasource = datasource
self.endpoint = 'http://' + self.ip + ':' + self.port + '/' + self.datasource
def get_url(self):
return self.endpoint
def set_url(self, endpoint):
self.endpoint = endpoint
class RequestHandler:
def __init__(self, config):
self.config = config
def request(self, query):
params = {'query': query}
r = requests.get(self.config.get_url(), params)
return r.json()
def post_query(self, query):
params = {'query': query}
r = requests.post(self.config.get_url(), params)
return r.json()
def post(self, params, headers):
r = requests.post(self.config.get_url(), params, headers=headers)
return r.json()
def post_minimal(self, params):
r = requests.post(self.config.get_url(), data=json.dumps(params), headers={'Content-type': 'application/json'})
return r.json()