如何处理Google端点方法参数?

时间:2015-12-02 21:51:06

标签: python python-2.7 google-app-engine

如果我有端点方法:

@endpoints.method(ProfileMiniForm, ProfileForm,
        path='profile', http_method='POST', name='saveProfile')
def saveProfile(self, request):
    """Update & return user profile."""
    return self._doProfile(request)

在saveProfile函数中,当它接收请求时,它是否接受了ProfileMiniform的实例?

1 个答案:

答案 0 :(得分:1)

是的,我假设它基于您编写的protorpc消息类。

让我们试试这里的例子:

class ProfileMiniForm(messages.Message):
    message = messages.StringField(1)

class ProfileForm(messages.Message):
    response = messages.StringField(1)

如果这些是您的输入和输出消息类,您将访问来自此类请求的message数据成员:

@endpoints.method(ProfileMiniForm, ProfileForm,
        path='profile', http_method='POST', name='saveProfile')
def saveProfile(self, request):
    """Update & return user profile."""
    # get the ProfileMiniForm instance data in the request object 
    message = request.message
    # return message object here, in this case a ProfileForm instance
    return ProfileForm(response = message)