python-2.7google-app-enginegoogle-cloud-messaginggoogle-cloud-endpointsprotorpc

Google Cloud Endpoints Multi Get


I have an EndpointsModel from Endpoints Proto Datastore API called Resource and I am requesting 10 items using: Resource.query().fetch(10).

The problem is it is returning an array of Resources but according to the documentation for "Creating an Endpoints API" I need to return an array of of messages.

https://cloud.google.com/appengine/docs/python/endpoints/create_api

Proto RPC messages with Google Cloud Enpoints

Is there a standard way to convert my array of models to messages or is a for loop the most efficient way to go about this?

Thanks in advance!


Solution

  • I did a bit more digging and I found an example by Google Cloud Platform on GitHub ( https://github.com/GoogleCloudPlatform/appengine-endpoints-tictactoe-python ). tictactoe_api.py uses a for loop on the returning NDB values and a custom to_message() function in models.py to convert them to a protoRPC message.