google-app-enginegoogle-cloud-datastoreapp-engine-ndbendpoints-proto-datastore

Updating contents of Endpoints class using endpoints-proto-datastore


i have a class which inherits from EndpointsModel

class User( EndpointsModel ):
  name = ndb.StructuredProperty( Name, required=True )
  dateOfBirth = ndb.DateProperty(required=True)
  userName = ndb.StringProperty( required=True )
  emailId = ndb.StringProperty( required=True )

Now, suppose i want to update the name for some user with some username. Since, the methods for User expects a User object as input and output, do i have to create a separate message class for name and then use it to update name like i would do if i was not using endpoints-proto-datastore ?


Solution

  • You can define request_fields in your API method to limit the "request message" to a subset of the fields in User

    @User.method(path='/user/{id}',
                 http_method='PUT',
                 name='update',
                 request_fields=('id', 'name'))
    def update_user(self, user):
        ...