flask-classy icon indicating copy to clipboard operation
flask-classy copied to clipboard

Added make_response to FlaskView as a class method

Open ryanolson opened this issue 11 years ago • 3 comments

I've added the ability to override Flask's make_response function by adding a new make_response class method to FlaskView.

The motivation is to provide an final and inheritable "decorator-like" function that wraps the view's response.

Decorators are inheritable; however, if a subclass wishes to modify the decorator list, they need to be aware of the parents decorators to do so.

I'm not sure if this function should be an instance function or a class method. I've created it as a class method; however, I'd be willing to change it to an instance method to provide easier and cleaner subclassing.

My personal motivation for this pull request is to replace Flask-RESTful's MethodView with FlaskView.

I like the design where the API views return the data directly and the make_response provides the final conversion to the output representation requested.

ryanolson avatar Jul 22 '14 19:07 ryanolson

Maybe you can handle that in a serialization middleware. I use Flask RESTful MethodView as well, not only for this though and I haven't decided yet which is best behavior.

EvaSDK avatar Jul 23 '14 15:07 EvaSDK

@apiguy - thoughts?

ryanolson avatar Aug 27 '14 01:08 ryanolson

FWIW I like @ryanolson 's fix of allowing the View to override the make_response method

dwcaraway avatar Nov 26 '14 14:11 dwcaraway