support application/json request body
This commit is contained in:
parent
14c8345740
commit
808b72316a
1 changed files with 12 additions and 3 deletions
|
@ -83,9 +83,18 @@ class ApiHandler(tornado.web.RequestHandler):
|
||||||
context = self._context
|
context = self._context
|
||||||
if context is None:
|
if context is None:
|
||||||
context = defaultcontext
|
context = defaultcontext
|
||||||
action = request.arguments.get('action', [None])[0].decode('utf-8')
|
action = None
|
||||||
data = request.arguments.get('data', [b'{}'])[0]
|
if request.headers.get('Content-Type') == 'application/json':
|
||||||
data = json.loads(data.decode('utf-8')) if data else {}
|
try:
|
||||||
|
r = json.loads(request.body.decode())
|
||||||
|
action = r['action']
|
||||||
|
data = r['data']
|
||||||
|
except:
|
||||||
|
action = None
|
||||||
|
if not action:
|
||||||
|
action = request.arguments.get('action', [None])[0].decode('utf-8')
|
||||||
|
data = request.arguments.get('data', [b'{}'])[0]
|
||||||
|
data = json.loads(data.decode('utf-8')) if data else {}
|
||||||
if not action:
|
if not action:
|
||||||
methods = list(actions.keys())
|
methods = list(actions.keys())
|
||||||
api = []
|
api = []
|
||||||
|
|
Loading…
Reference in a new issue