flask-restplus-server-example
flask-restplus-server-example copied to clipboard
Response fields filtering/masking
Hi,
I'd like to know if there is an easy way to modify the patch to mask the response fields by a query parameter (like /api/users?fields=email,name), I've tried the restplus approach with the X-Fields but that no longer works with the patch.
I thought the way to go would be to use a schema factory as shown in then marshmallow docs: http://webargs.readthedocs.io/en/latest/advanced.html. But I don't understand the code base enough to intervene.
There is no built-in functionality at the moment, though I see the value in such a feature. Currently, given you may not want to spend too much time on this, I would recommend you add a parameter to the users endpoint accepting fields (marshmallow List field type will match your needs) and then in the endpoint itself you return a serialized output:
return schemas.BaseUserSchema(only=fields, many=True).dump(users).data
Perfect, sounds fine. It did seem a little tricky to route the request object down to the response decorator, you're probably right, this would be time consuming.
Thanks for your quick reply.
I'm interested on this feature as well, I see a big value on having this OOO on flask-restplus.