I have a Flask application which uses the connexion library to create the API.
The application will not just be a web service, but will also be a front end app, consuming its own API rather than making direct database calls.
How do I call, from within a Flask application, an endpoint defined as a web service within the same application?
# Create a URL route in our application for "/products"
@app.route('/products')
def products():
"""
This function just responds to the browser ULR
localhost:5000/
:return: the rendered template 'home.html'
"""
r = requests.get('api/read/products')
print(r.text)
return render_template('products.html', page_title="Regulatory Analytics Home", products="")
This is simply generating:
requests.exceptions.MissingSchema: Invalid URL 'api/read/products': No schema supplied. Perhaps you meant http://api/read/products?
Changing the path to:
r = requests.get('/api/read/products')
doesn't work. My products.html file is in a /templates folder, so I tried.
r = requests.get('../api/read/products')
And this didn't work either, as I assumed I may need a relative path to the root of the site from where the products.html is served from.