i have simple http client in python send http post request this:
import json import urllib2 collections import defaultdict dd data = dd(str) req = urllib2.request('http://myendpoint/test') data["input"] = "hello world!" response = urllib2.urlopen(req, json.dumps(data)) on server side flask, can define simple function
from flask import request @app.route('/test', methods = ['post']) def test(): output = dd() data = request.json and data on server same dictionary data on client side.
however, moving klein, server code looks this:
@app.route('/test', methods = ['post']) @inlinecallbacks def test(request): output = dd() data = request.json <=== doesn't work and request that's been used in klein not support same function. wonder there way json in klein in same way got in flask? thank reading question.
asaik klein doesn't give direct access json data, can use code access it:
import json @app.route('/test', methods = ['post']) @inlinecallbacks def test(request): output = dd() data = json.loads(request.content.read()) # <=== work