How do you return a Partial response in app engine python endpoints?

浪子不回头ぞ 提交于 2019-12-12 01:05:57

问题


I am learning endpoints and saw that other Google APIs have this "fields" query attribute.
Also it appears in the api explorer.

I would like to get a partial response for my api also, but when using the fields selector from the api explorer it is simply ignored by the server.
Do I need to implement something in the server side?
Haven't found anything in the docs.
Any help is welcome.


回答1:


From what I gather, Google has enabled partial response for their APIs, but has not yet explained how to enable it for custom APIs. I'm assuming if they do let us know, it might entail annotations, and possibly overriding a method or two.

I've been looking also, to no avail. I've been looking into this just due to a related question, where I'd like to know how to force the JSON object in the response from my google Endpoint API, to include even the members of the class that are null valued. I was trying to see if anything would be returned if I used a partial response with a field indicated that was null.. would the response have the property at least, or would it still not even exist as a property.

Anyway, this lead me into the same research, and I do not believe we can enable partial responses in our own APIs yet.




回答2:


You can return a partial response by defining the parameter in @MyModel.method

@MyModel.method(path='mymodel',
                  http_method='POST',
                  name='mymodel.insert',
                  response_fields=('model_id', 'date_time'))
def mymodel_insert(self, mymodel):
    mymodel.put()
    return mymodel

Check out this tutorial Endpoints tutorial



来源:https://stackoverflow.com/questions/21516287/how-do-you-return-a-partial-response-in-app-engine-python-endpoints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!