Google Endpoints方法参数如何处理?

2024-10-02 12:37:20 发布

您现在位置:Python中文网/ 问答频道 /正文

如果我有Endpoints方法:

@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的实例


Tags: path方法nameselfhttpreturnrequestprofile
1条回答
网友
1楼 · 发布于 2024-10-02 12:37:20

是的,我假设它基于您编写的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) 

相关问题 更多 >

    热门问题