Reputation: 5238
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
Upvotes: 1
Views: 467
Reputation: 10163
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.
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>
Upvotes: 1