xDr_Johnx
xDr_Johnx

Reputation: 77

How are Google Endpoints Method Arguments Handled?

If I have the Endpoints method:

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

In the saveProfile function, when it takes in request, is it taking in an instance of ProfileMiniform?

Upvotes: 0

Views: 25

Answers (1)

Kris
Kris

Reputation: 10297

Yeah, which I assume is based on a protorpc message class that you wrote.

So let's try for an example here:

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

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

If these are your input and output message classes, you would access the message data member coming from a request like this:

@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) 

Upvotes: 1

Related Questions