I have an Python Flask api that is being called in a React app using Axiom. I'm using the following code in NameForm component to handle requests from my Flask api. import React from 'react'; import axios from 'axios';
class NameForm extends React.Component {
constructor(props) {
super(props);
this.state = {value: ''};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit(event) {
axios.get('http://127.0.0.1:5000/api/'+this.state.value,)
.then(function (response) {
console.log(response.data);
console.log(response.status);
})
.catch(function (error) {
console.log(error);
});
This code sometimes returns nothing and sometimes returns the contents from my Flask API depending on what content I generate on the backend.
Here is my backend code. For all requests, I see the request being made on the backend and see the data being printed. However, for some requests, I don't see anything returned to the front-end. The request that returns something when I have the first function is_original, but when I include the other functions below, I see nothing on the front-end. I'm very confused as to why some json is being returned while some other json is not being returned.
import json
from flask import Flask
from flask import jsonify
from dog_matcher import *
app = Flask(__name__)
@app.route("/api/<name>")
def hello(name):
data = {}
name = name.capitalize()
data['is_original']= is_original(name, names_file[1:10])
data['meta_names']= get_metaphone_closest(name, names_file)
data['leven_names'] = get_levenshtein_closest(name, names_file)
data['jaro_names']= get_jaro_closest(name, names_file)
data['soundex']= get_soundex_closest(name, names_file)
print(data)
return jsonify(data)
if __name__ == "__main__":
app.run(debug=True)
On the server, the following content is printed for the request "Jim" from the front-end. Nothing is returned on the frontend.
{'meta_names': [(0, 'Jaime'), (0, 'Jammy'), (0, 'Jamy'), (0, 'Jayme'), (0, 'Gim'), (0, 'Gimmo'), (0, 'Gimmy'), (0, 'Gimo'), (0, 'Jim'), (0, 'Jimmi')], 'is_original': True, 'leven_names': [(1.0, 'Jim'), (0.9166666666666666, 'Jimy'), (0.8666666666666667, 'Jaime'), (0.8666666666666667, 'Jimbo'), (0.8666666666666667, 'Jimmi'), (0.8666666666666667, 'Jimmy'), (0.8333333333333334, 'Jaimie'), (0.8095238095238096, 'Jim-Jim'), (0.7777777777777777, 'Gim'), (0.7777777777777777, 'Kim')], 'jaro_names': [(1.0, 'Jim'), (0.9166666666666666, 'Jimy'), (0.8666666666666667, 'Jaime'), (0.8666666666666667, 'Jimbo'), (0.8666666666666667, 'Jimmi'), (0.8666666666666667, 'Jimmy'), (0.8333333333333334, 'Jaimie'), (0.8095238095238096, 'Jim-Jim'), (0.7777777777777777, 'Gim'), (0.7777777777777777, 'Kim')], 'soundex': [(0, 'Jahn'), (0, 'Jan'), (0, 'Jann'), (0, 'Jean'), (0, 'Jim'), (0, 'Jin'), (0, 'Jiwan'), (0, 'Johann'), (0, 'John'), (0, 'Jon')]} 127.0.0.1 - - [26/Apr/2017 00:08:26] "GET /api/Jim HTTP/1.1" 200 -