简体   繁体   English

Google App Engine Api和端点版本控制

[英]Google App Engine Api and Endpoints versioning

I'm having some troubles finding proper way of handling multiple versions of remote.Service api in my application. 我在我的应用程序中找到正确的方法来处理多个版本的remote.Service api时遇到了一些麻烦。

class MyService(Service):
   @endpoints.method(
        endpoints.ResourceContainer(
            something=protorpc.messages.StringField(1, required=True),
        ),
        message_types.VoidMessage,
    )
    def do_stuff(self, request):
        ... implement do_stuff ...

class MyBetterService(MyService):
    @endpoints.method(
        endpoints.ResourceContainer(
            some_other_name=protorpc.messages.StringField(1, required=True),
        ),
        message_types.VoidMessage,
    )
    def do_stuff(self, request):
        # ...other way of doing stuff
        return message_types.VoidMessage()

When trying to make libraries i got this error: 在尝试创建库时出现此错误:

protorpc.remote.ServiceDefinitionError: Do not use method decorator when overloading remote method do_stuff on service MyBetterService.

Is there way for overriding method in next version of API? 在下一版API中是否有覆盖方法的方法?

Overridden method may take other request parameters? 重写方法可能需要其他请求参数?

Is there possibility of adding only one endpoint in different version to existing api? 是否有可能在现有API中只添加一个不同版本的端点?

The endpoints service classes are written such that once you define a public interface method you may not alter them in sub-classes. 编写端点服务类,一旦定义了公共接口方法,就不能在子类中更改它们。 Normally you should not define a new API version of a class as a sub-class unless it an exact super-set the interface of the super class. 通常,您不应该将类的新API版本定义为子类,除非它精确地超级设置超类的接口。

In the case where the new version is a super-set you may use redefine interface methods which will automatically inherit the attributes of the parent method. 在新版本是超集的情况下,您可以使用重新定义的接口方法,这将自动继承父方法的属性。 For example: 例如:

class MyService(Service):
   @endpoints.method(
        endpoints.ResourceContainer(
            something=protorpc.messages.StringField(1, required=True),
        ),
        message_types.VoidMessage,
    )
    def do_stuff(self, request):
        ... implement do_stuff ...

class MyBetterService(MyService):
    def do_stuff(self, request):
        # ...other way of doing stuff
        return message_types.VoidMessage()

   @endpoints.method(
        endpoints.ResourceContainer(
            something=protorpc.messages.IntegerField(1, required=True),
        ),
        message_types.VoidMessage,
    )
    def do_more_stuff(self, request):
        ... implement do_more_stuff ...

There is no way to change the input-type for do_stuff() . 无法更改do_stuff()的输入类型。

In practice new API versions ought to be treated the same as a new API and have an independent Service class definition. 在实践中,新的API版本应该被视为与新API相同并且具有独立的Service类定义。 Think of an API really as an interface. 将API真正视为一个接口。 While two classes should not share a base class with common API method defintions, it does not mean that two classes may now share a common set of functional classes. 虽然两个类不应该共享具有常见API方法定义的基类,但这并不意味着两个类现在可以共享一组通用的函数类。

When I've built services I've implemented the API versions as separate classes, even if I've had to duplicate many of the method signatures. 当我构建服务时,我已经将API版本实现为单独的类,即使我必须复制许多方法签名。 Underneath the service, however, I implemented a system of objects that perform the same actions entirely independently of the interface and API message types. 但是,在服务下面,我实现了一个对象系统,它完全独立于接口和API消息类型执行相同的操作。 This allows two API versions to share significant parts of the implementation. 这允许两个API版本共享实现的重要部分。

For example: 例如:

from mysystem import MyImplementation

class MyService(Service):
   @endpoints.method(
        endpoints.ResourceContainer(
            something=protorpc.messages.StringField(1, required=True),
        ),
        message_types.VoidMessage,
    )
    def do_stuff(self, request):
      MyImplementation.do_stuff(request.something)

class MyBetterService(Service):
   @endpoints.method(
        endpoints.ResourceContainer(
            something=protorpc.messages.IntegerField(1, required=True),
        ),
        message_types.VoidMessage,
    )
    def do_stuff(self, request):
      MyImplementation.do_stuff(self.lookup_string(request.something))

In this model, I think of the API as being responsible for marshaling information between the service interface and the actual underlying system, rather than an actual implementation. 在这个模型中,我认为API负责在服务接口和实际底层系统之间编组信息,而不是实际的实现。

While explicitly copying each method for each new implementation might seem like a lot of work, in practice it's usually a very small portion of what your overall service is supposed to do. 虽然为每个新实现明确地复制每个方法可能看起来很多工作,但实际上它通常只是整个服务应该做的一小部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google App Engine端点api在localhost中不起作用 - Google app engine endpoints api not working in localhost Google App Engine配置端点API - Google App Engine configuring Endpoints API 数据存储区中的Google App Engine版本控制 - Google App Engine Versioning in the Datastore 在Google App Engine云端点内部调用Drive API - Make calls to Drive API inside of a Google App Engine Cloud Endpoints Google App Engine-端点API-从另一个App Engine应用程序使用-python - Google App Engine - Endpoints API - Consuming from another App Engine App -python 在没有App Engine的情况下运行Google Cloud端点 - Running google cloud endpoints without App Engine Google Cloud Endpoints V2多类API错误App Engine标准 - Google Cloud Endpoints V2 multi-class API error App Engine Standard 如何使用OAuth从Python应用程序访问Google App Engine端点API? - How can I access Google App Engine endpoints API from Python application with use OAuth? 表情符号字符会破坏Google App Engine和Endpoints库中的文本(Python中的Engine,端点库位于Android上) - Emoji characters destroys text in Google App Engine and Endpoints library (Engine in Python, endpoints library is on Android) 如何在Google App Engine端点中返回数组响应 - How to return an array response in Google App Engine endpoints
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM