I have this code to POST and save a digest to redis, and retrieve it from redis on a GET. This uses Python and Flask, of course.
@app.route("/message/<shasum>", methods=['GET'])
def get_message(shasum):
message = redis.get(shasum)
if message:
return jsonify(message=message)
else:
abort(404)
@app.route("/digest", methods=['POST'])
def get_digest():
if request.headers['Content-Type'] == 'application/json':
message = json.loads(request.data)
sha = sha256(message['message'].encode('utf-8')).hexdigest()
redis.set(sha, message['message'])
return (jsonify(digest=sha), 201)
else:
return (jsonify(message="Bad Request"), 400 )
what else can I do to improve the performance of this little piece of code, specifically on the POST side and can it be improved on the GET side too?