我正在通过 Google Cloud Endpoints 和 endpoints-proto-datastore 库编写 API。
这是我的模型:
class Domain(EndpointsModel):
_message_fields_schema = ('id', 'name', 'enabled', 'adminEmails')
name = ndb.StringProperty(required=True)
enabled = ndb.BooleanProperty(required=True)
adminEmails = ndb.StringProperty(repeated=True)
这是我的删除方法:
@Domain.method(request_fields=('id',), path='domains/{id}', http_method='DELETE', name='domain.delete')
def delete_domain(self, domain):
if not domain.from_datastore:
raise endpoints.NotFoundException('Domain not found.')
domain._key.delete()
return domain
我可以退回模型本身以外的其他东西吗?如何返回特定的 HTTP 状态代码或类似 VoidMessage 的内容?