The Endpoints Proto Datastore API provides an abstraction that allows
existing model classes to be used with Google Cloud Endpoints. By extending the
functionality provided by
ndb.Model class and the
library, this library allows you to directly interact with model entities in your
API methods rather than ProtoRPC requests.
For example, instead of:
@endpoints.method(MyModelMessage, MyModelMessage, path='mymodel', http_method='POST', name='mymodel.insert') def InsertModel(self, request): my_model = MyModel(attr1=request.attr1, attr2=request.attr2, ...) transformed_model = DoSomething(my_model) return MyModelMessage(attr1=transformed_model.attr1, attr2=transformed_model.attr2, ...)
we can directly use the entity in the request:
@MyModel.method(path='mymodel', http_method='POST', name='mymodel.insert') def InsertModel(self, my_model): return DoSomething(my_model)
without ever even having to define a ProtoRPC message class!
The Endpoints Proto Datastore API currently supports only NDB classes. Using the Endpoints Proto Datastore API, custom models and properties can be created to specify exactly how data that is sent to and sent by APIs written with Google Cloud Endpoints will be structured.
Using a provided method, request and response message schemas can be defined that allow automatic serialization and deserialization of Cloud Endpoints API payloads into model entities. In another provided method, the same can be done to serialize and deserialize into model query objects.
Through the samples provided in this sample, a reference is defined, building up from the simplest use case to the most complex.