Cloud Endpoints with Multiple Services Classes

后端 未结 5 708
梦谈多话
梦谈多话 2021-01-03 02:51

I am starting to use Google Cloud Endpoints and I am running in a problem when specifying multiple services classes. Any idea how to get this working?

ApiCon         


        
5条回答
  •  执笔经年
    2021-01-03 03:37

    The correct way is to create an api object and use the collection

    api_root = endpoints.api(name='myservice', version='v1', description='MyService API')
    
    @api_root.collection(resource_name='first')
    class FirstService(remote.Service):
      ...
    
    
    @api_root.collection(resource_name='second')
    class SecondService(remote.Service):
      ...
    

    where resource name would be inserted in front of method names so that you could use

      @endpoints.method(name='method', ...)
      def MyMethod(self, request):
        ...
    

    instead of

      @endpoints.method(name='first.method', ...)
      def MyMethod(self, request):
        ...
    

    Putting this in the API server:

    The api_root object is equivalent to a remote.Service class decorated with endpoints.api, so you can simply include it in the endpoints.api_server list. For example:

    application = endpoints.api_server([api_root, ...])
    

提交回复
热议问题