具有多个服务类的云端点 [英] Cloud Endpoints with Multiple Services Classes

查看:79
本文介绍了具有多个服务类的云端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用Google Cloud Endpoints,并且在指定多个服务类时遇到问题。任何想法如何得到这个工作?

  ApiConfigurationError:试图实现服务myservice版本v1,多个类不是兼容。有关示例,请参阅api()的docstring以了解如何实现多类API。 

这就是我创建我的端点服务器的方式。

  AVAILABLE_SERVICES = [
FirstService,
SecondService
]

app = endpoints.api_server(AVAILABLE_SERVICES)

对于每个服务类我都是这样做的:

< pre $ @ endpoints.api(name ='myservice',version ='v1',description ='MyService API')
FirstService(remote.Service):
...

@ endpoints.api(name ='myservice',version ='v1',description ='MyService API')
class SecondService(remote.Service):
...

这些工作都完全分开,但我不确定如何获得他们正在合并他们的工作。



非常感谢。

解决方案

正确的方法是创建一个 api 对象并使用集合

  api_root = endpoints.api (name ='myservice',version ='v1',description ='MyService API')

@ api_root.collection(resource_name ='first')
FirstService(remote.Service) :
...


@ api_root.collection(resource_name ='second')
class SecondService(remote.Service):
...

其中资源名称将插入方法名称的前面,以便您可以使用

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

而不是

<$ p $
def MyMethod(self,request):
...
@ endpoints.method(name ='first.method',...) code>



将其放入API服务器:



api_root 对象相当于用 endpoints.api 装饰的 remote.Service ,所以你可以简单地将它包含在 endpoints.api_server l中IST。例如:

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


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?

ApiConfigurationError: Attempting to implement service myservice, version v1, with multiple classes that aren't compatible. See docstring for api() for examples how to implement a multi-class API.

This is how I am creating my endpoint server.

AVAILABLE_SERVICES = [
  FirstService,
  SecondService
]

app = endpoints.api_server(AVAILABLE_SERVICES)

and for every service class I am doing this:

@endpoints.api(name='myservice', version='v1', description='MyService API')
class FirstService(remote.Service):
...

@endpoints.api(name='myservice', version='v1', description='MyService API')
class SecondService(remote.Service):
...

Each one of these work perfectly separately, but I am not sure how to get them working when combining them.

Thanks a lot.

解决方案

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, ...])

这篇关于具有多个服务类的云端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆