Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloud Endpoints with Multiple Services Classes

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.

like image 928
mkhatib Avatar asked Apr 23 '13 05:04

mkhatib


People also ask

What is the difference between Cloud Endpoints and Apigee edge?

For Endpoints, the Service Manager proxy is deployed in your own infrastructure (be it App Engine, Cloud Run, a Compute VM, or non-GCP machines). For Apigee, the proxies are deployed in their own infrastructure. There are a bunch of other differences, but where it runs is the one that stands out for me.

What are endpoints in cloud computing?

An endpoint is a remote computing device that communicates back and forth with a network to which it is connected. Examples of endpoints include: Desktops. Laptops. Smartphones.

What is the difference between endpoint and API?

An endpoint is a component of an API, while an API is a set of rules that allow two applications to share resources. Endpoints are the locations of the resources, and the API uses endpoint URLs to retrieve the requested resources.


2 Answers

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, ...])
like image 66
bossylobster Avatar answered Sep 21 '22 20:09

bossylobster


If I'm not mistaken, you should give different names to each service, so you'll be able to access both, each one with the specific "address".

@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):
...
like image 28
Mario Jorge Valle Avatar answered Sep 17 '22 20:09

Mario Jorge Valle