Proper way to suppress a field from every element in a collection in python-eve
Question
I would like to prevent a certain largish field in a collection of documents from being returned as part of the basic resource request in an eve app. What is the proper way of doing this? I was thinking of using an on_fetch hook but thought maybe there was some way of specifying this in the schema instead.
Solution
Projections can also be used to Limit the Fieldset Exposed by the API:
When setting the datasource property for any given resource endpoint it is possible to explicitly exclude fields (of media type, but also of any other type really) from default responses:
people = {
'datasource': {
'projection': {'image': 0}
},
...
}
OTHER TIPS
http://python-eve.org/features.html#leveraging-projections-to-optimize-the-handling-of-media-files
See the above suggestion in the eve docs:
$ curl -i http://example.com/people/<id>?projection={"image": 0}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow