In Flask, I have an Eve API running under endpoints like /api/v1/Widgets
I can query that from eg Javascript, but I don't know how to properly query that API from elsewhere within my Flask app.
Just now for example, if I need to search Widgets in one of my routes, then I'm loading the requests
module and querying the API using a separate http request, and dealing with the JSON returned.
@app.route('/hello')
def show_hello():
resp = requests.get('http://example.com/api/v1/Widgets')
return jsonify({'results': resp.json()})
That's surely very inefficient and it seems like there must be something like
my_endpoint = app.Eve.endpoint('Widgets') # not real
return jsonify({'results': my_endpoint.search()}) # not real
But I don't know what that is. Could someone help me understand if/how I can make queries directly into my Eve endpoints from with my normal Flask app routes?
You can use app.test_client.get()
which is however rate limited, authenticated and raises pre-request events.
With v0.7 (currently on the develop
branch ) you can use get_internal
. This method is not rate limited, authentication is not checked and pre-request events are not raised. Usage example:
from eve.methods.get import get_internal
payload = get_internal(endpoint)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.