2014-03-29 103 views
0

我正在使用'endpoints-proto-datastore'库,并且在如何向我的请求中添加额外参数时丢失了一些内容。Google Cloud Endpoints添加额外参数

基本上我想添加这些字段[ID,标记]与ID是必需的。 Blossom.io在做类似的事情,在这里Blossom.io Api

这里是我的Post方法

@Doctor.method(path='doctor', http_method='POST', name='doctor.insert') 
    def DoctorInsert(self, doctor): 

@Edit

没有始祖数据存储库:

request = endpoints.ResourceContainer(
    message_types.VoidMessage, 
    id=messages.IntegerField(1,variant=messages.Variant.INT32), 
    token=messages.IntegerField(2, variant=messages.Variant.INT32) 
) 

@endpoints.method(request, response, 
        path='doctor/{id}', http_method='POST', 
        name='doctor.insert') 

哪有我使用原型数据存储库做同样的事情吗?

回答

1

我这样做的方式是将另一个属性添加到用@EndpointsAliasProperty和setter装饰的模型中。我不会将其称为ID,因为它可能会与App Engine内置ID混淆。

class Doctor(EndpointsModel): 
    ... 
    @EndpointsAliasProperty(
     setter=set_doctorid, property_type=messages.StringField 
    ) 
    def doctorid(self): 
     #Logic to retrieve the ID 
     return doctorid 

    def set_doctorid(self, value): 
     #The ID will be in the value, assign and store it in your model 
+0

我现在可以通过做'path ='doctor/{doctorid}来显示ID,但是如何添加另一个参数而不需要? – Erevald

+0

编辑我的帖子。 – Erevald

相关问题