I am looking to store JSON data in a variable using Axios in Javascript. The JSON endpoint is generated by my own server's route http://123.4.5.6:7890/json
. I have been successful with this function:
async function getClasses() {
const res = await axios.get('http://123.4.5.6:7890/json');
}
However, I understand that this may not work if someone else accesses my project from their server. What should I use instead of 'http://' in the code? My mentor suggested 'http://localhost:5000/json', but when I tried it, I encountered an error.
https://i.stack.imgur.com/qE5zS.png
This is the python code for my JSON route:
@app.route('/json')
def display_json():
"""view/signup for available yoga classes using API"""
serialized_classes = [c.serialize() for c in Classes.query.all()]
return jsonify(serialized_classes)
Accessing the route in my browser successfully displays the JSON data. Thank you in advance for any assistance provided.