I have build a very very simple server to learn Flask and Jupiter and see How I made work them togheter:
`#%% ALL server logic
from flask import Flask,jsonify,request,make_response
app = Flask(__name__)
@app.route('/')
def nakedRoute():
print('inside the teapot')
return "I'm a teapot", 418
@app.route('/echo/', methods=['POST'])
def serverAPI_ejemplo():
try:
if not request.is_json:
return make_response(jsonify({"error": "I was expecting a JSON"}), 400)
data = request.json['key'] + 1
return jsonify({"key":data}), 200 # Código de estado 200 (OK)
except Exception as e:
return make_response(jsonify({"error": 33}), 500)
#%% Mount the server
if __name__ == "__main__":
app.run(port=5000, debug=True)
# %% TEST naked router
with app.app_context():
result= nakedRoute()
print(result)
# %% TEST /echo/ for error 500
with app.app_context():
result= serverAPI_ejemplo()
print(result)
In that sense, I can load all the funcionality in Jupiter within the first cell, and play with the code in real time
Well, all this work as soon as I expect to add a Json to the CALL
# %% TEST /echo/ for a JSON
with app.app_context():
my_JSON = {"key":33}
#...???
result= serverAPI_ejemplo()
print(result)`
so far, I have not been able to complete the code to be able to call serverAPI_ejemplo, and get the JSON pas trough
New contributor
AsperusMe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.