1

For some reason I am unable to read request parameters when using http_method=GET instead of POST.

@endpoints.method(RequestMessage,
                  ResponseMessage,
                  name='get',
                  path='mypath',
                  http_method='GET')
def get_challenge(self, request):
    # This is None in http_method=GET but works on POST
    print request.my_message_field

My message class is like this:

class MyMessage(messages.Message):
    id = messages.StringField(1)
    name = messages.StringField(2)

class RequestMessage(messages.Message):
    my_message_field = messages.MessageField(MyMessage, 1)

I am testing the API through the API Explorer. Any idea if I am doing something wrong or what?

Thanks

mkhatib
  • 5,089
  • 2
  • 26
  • 35

1 Answers1

1

The parameters should be showing up as my_message_field.id and my_message_field.name.

The fundamental difference is that GET has no payload and POST does. As a result, your parameter namespace must be "flat" instead of nested JSON. So to accomodate this we flatten out the parameters as I mentioned above.

UPDATE:

This must have been an issue with something not getting correctly ported to devappserver. I added a logger to endpoints.apiserving to determine what was passed from the API frontend to the App Engine backend:

In production:

'{"my_message_field":{"id":"x","name":"y"}}'

In devappserver2:

'{"my_message_field.name": ["y"], "my_message_field.id": ["x"]}'

When trying to parse via

from protorpc import remote
protocols = remote.Protocols.get_default()
json_protocol = protocols.lookup_by_content_type('application/json')
json_protocol.decode_message(RequestMessage, payload)

which is what the api_server does, this is what occurred

In production:

<RequestMessage
 my_message_field: <MyMessage
 id: u'x'
 name: u'y'>>

In devappserver2:

<RequestMessage>
bossylobster
  • 9,993
  • 1
  • 42
  • 61
  • Does that mean it's a bug in devappserver2? Should we file a bug somewhere? Thanks for the explanation. – mkhatib Apr 28 '13 at 21:18
  • 1
    I've got it handled. I think it may be related to a feature/patch from the old `dev_appserver` that didn't get ported to `devappserver2` in time for a release. – bossylobster Apr 28 '13 at 23:06
  • 2
    @mkhatib I confirmed this has been correctly ported over to `devappserver2` and should be working in the next release. Sorry for the broken behavior. If it's really crucial it'll be working in `old_dev_appserver.py` for now :S – bossylobster Apr 29 '13 at 21:35
  • Thanks @bossylobster for the detailed replies. It's not crucial, I can work with POST for now. – mkhatib May 02 '13 at 05:09