If I understand, what you want is to run custom code before/after requests. To do that, you can use Event Hooks to set callbacks before/after request or database events.
An example to run your compute_average
before any GET
to users
resource:
def compute_average(request, lookup)
# your code
app = Eve()
app.on_pre_GET_users += compute_average
app.run()
Your function parameters would change a little. As the documentation states, callbacks to a specific resource receive the original flask.request
object and the current lookup
dictionary as arguments.
But you can perform mongodb
queries in your code as usual if you need to retrieve documents to perform your calculations.
Check the documentation for more details.