Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
API Request from React frontend to Flask backend returns null on the first request only

I have a React frontend that communicates with a Flask backend, and for the most part it works fine. However, every time I make the first API request, the backend will send an error. After that, everything works fine. I suspect that there is some issue with my JavaScript not waiting for the API response properly, but I do not know exactly what is going on.

The code for my API request is listed below:

const handleSubmit= (e) => {
    e.preventDefault();
    const data = {"locationType": locationType, 
                  "numLocations": numLocations, 
                  "city": city};
    alert("Successfully submitted!");
    axios
      .post(url, data)
      .then(res => {
        setResult(JSON.stringify(res.data.resultsList));
        //console.log(result);
        addShops(result);
      })
      .catch(err => console.log(err));
      return JSON.stringify(result);
  }

In addition, the code for my POST response is listed here:

  def post(self):
    print(self)
    parser = reqparse.RequestParser()
    parser.add_argument('locationType', type=str)
    parser.add_argument('numLocations', type=int)
    parser.add_argument('city', type=str)

    args = parser.parse_args()
    location = args['locationType']
    num_locations = args['numLocations']
    city = args['city']

    if location:
      message = calculate(location, num_locations, city)
    else:
      message = "No Msg"
    
    return message

Please let me know if more information is needed to answer the question! Thank you!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!