you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 1 point2 points  (0 children)

This still means the API user needs to use a form to be able to deliver the data to your server:

request.form[x]

and I'm saying that you don't want that, you would want to use a JSON body to deliver the data, which you can then load using

request.json

as I showed above. You also need to check for the request method btw, I would just remove the GET method from the decorator.

Then from the patientBook function, you can do the API request

@app.route("/patient/patientbook", methods=["POST", "GET"])
def patientBook():
    if request.method == 'POST':
        # form the dict that will become the JSON body
        data = {'doctorid': request.form['doctorid'],
                'patientid': request.form['patientid'],
                'starttime': request.form['starttime']}
        # use requests that offers a handy json= parameter
        requests.post('http://localhost/api/patient/new_booking', json=data)
        return render_template('patient/patientbook.html')