Cloud endpoints with multiple service classes

I am starting to use the endpoints of Google Cloud and I am having trouble specifying multiple classes of services. Any idea how to do this?

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 create my destination server.

AVAILABLE_SERVICES = [
  FirstService,
  SecondService
]

app = endpoints.api_server(AVAILABLE_SERVICES)

and for each class of service I do 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 of them works fine individually, but I'm not sure how to get them to work when combined.

Many thanks.

+5
source share
5 answers

The right way is to create an object apiand usecollection

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 the resource name will be inserted before the method names so you can use

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

instead

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

Put this on the API server:

api_root remote.Service, endpoints.api, endpoints.api_server. :

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

, , , "".

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

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

single api, . ( google ):

an_api = endpoints.api(name='library', version='v1.0')

@an_api.api_class(resource_name='shelves')
class Shelves(remote.Service):
...

@an_api.api_class(resource_name='books', path='books')
class Books(remote.Service):
...

APPLICATION = endpoints.api_server([an_api],
                               restricted=False)
+1

, ( , ...)

sdk google_appengine/google/appengine/ext/endpoints/api_backend_service.py 97:

        elif service_class != method_class:
          pass
#          raise api_config.ApiConfigurationError(
#              'SPI registered with multiple classes within one '
#              'configuration (%s and %s).  Each call to register_spi should '
#              'only contain the methods from a single class.  Call '
#              'repeatedly for multiple classes.' % (service_class,
#                                                    method_class))
    if service_class is not None:

In combination with this, I use the construct:

application = endpoints.api_server([FirstService, SecondService, ...])

Again, this will not work in production, you will get an exception there. Hope this answer is obsolete from a future fix.

It is confirmed that it is now outdated (verified against 1.8.2).

0
source

If it was Java ...

https://developers.google.com/appengine/docs/java/endpoints/multiclass

the cloud will not be easier.

0
source

All Articles