I have defined a custom Response format as per the Flask-RESTful documentation as follow.
app = Flask(__name__)
api = restful.Api(app)
@api.representation('application/octet-stream')
def binary(data, code, headers=None):
resp = api.make_response(data, code)
resp.headers.extend(headers or {})
return resp
api.add_resource(Foo, '/foo')
I have the following Resource class.
class Foo(restful.Resource):
def get(self):
return something
def put(self, fname):
return something
I want the get()
function to return the application/octet-stream
type and the put()
function to return the default application/json
.
How do I go about doing this? The documentation isn't very clear on this point.