Отказ от ответственности. Я еще не использовал серверную службу, ответ основан в основном на документации, а именно на Создание API, реализованного с несколькими классами
Похоже, что многоклассовые API по-прежнему используют одно сопоставление конечных точек в app.yaml
, соответствующее набору всех классов API. Из app.yaml в примере Github а>:
handlers:
# The endpoints handler must be mapped to /_ah/spi.
# Apps send requests to /_ah/api, but the endpoints service handles mapping
# those requests to /_ah/spi.
- url: /_ah/spi/.*
script: main.api
Путь /_ah/spi/BackendService.getApiConfigs
в первой ошибке, которую вы получаете, предполагает неспособность серверной службы получить конфигурацию серверной части (из которой будет получено каждое конкретное сопоставление классов), что соответствует отсутствию этого единственного сопоставления.
Вы можете разделить классы серверной части на несколько файлов. Для этого можно использовать следующий подход.
Единый/центральный файл записи серверных точек указан в app.yaml
:
# The endpoints handler must be mapped to /_ah/spi.
# Apps send requests to /_ah/api, but the endpoints service handles mapping
# those requests to /_ah/spi.
- url: /_ah/spi/.*
script: backend.api
Соответствующий файл backend.py
просто собирает фактические API из других файлов:
import endpoints
from backend1 import api_1
from backend2 import api_2
api = endpoints.api_server([api_1, api_2])
И эти файлы содержат соответствующие реализации API (скопированные/вставленные из примера github и слегка измененные для быстрого теста):
Файл backend1.py
:
import endpoints
from protorpc import messages
from protorpc import remote
class Request(messages.Message):
message = messages.StringField(1)
class Response(messages.Message):
message = messages.StringField(1)
api_1 = endpoints.api(name='library1', version='v1.0')
@api_1.api_class(resource_name='shelves')
class Shelves1(remote.Service):
@endpoints.method(Request, Response, path='list')
def list(self, request):
return Response()
# [START books]
@api_1.api_class(resource_name='books', path='books')
class Books1(remote.Service):
@endpoints.method(Request, Response, path='bookmark')
def bookmark(self, request):
return Response()
Файл backend2.py
:
import endpoints
from protorpc import messages
from protorpc import remote
class Request(messages.Message):
message = messages.StringField(1)
class Response(messages.Message):
message = messages.StringField(1)
api_2 = endpoints.api(name='library2', version='v2.0')
@api_2.api_class(resource_name='shelves')
class Shelves2(remote.Service):
@endpoints.method(Request, Response, path='list')
def list(self, request):
return Response()
# [START books]
@api_2.api_class(resource_name='books', path='books')
class Books2(remote.Service):
@endpoints.method(Request, Response, path='bookmark')
def bookmark(self, request):
return Response()
С помощью приведенного выше кода я смог увидеть 2 API в проводнике API сервера разработки:
![введите здесь описание изображения](https://i.stack.imgur.com/SwIPY.jpg)
Что произвело следующие журналы:
INFO 2016-06-21 15:52:24,945 module.py:812] default: "GET /_ah/api/static/proxy.html?jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.pEvOgGtQ_zc.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Frs%3DAGLTcCNv5bf7XiPy_xHPlP3A3K73m3QR2A HTTP/1.1" 200 8015
INFO 2016-06-21 15:52:25,058 module.py:812] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 200 5459
INFO 2016-06-21 15:52:25,070 module.py:812] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 200 5459
INFO 2016-06-21 15:52:25,470 module.py:812] default: "GET /_ah/api/discovery/v1/apis HTTP/1.1" 200 1516
INFO 2016-06-21 15:52:25,508 module.py:812] default: "GET /_ah/api/discovery/v1/apis HTTP/1.1" 200 1516
INFO 2016-06-21 15:52:25,813 module.py:812] default: "GET /_ah/api/static/proxy.html?jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.pEvOgGtQ_zc.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Frs%3DAGLTcCNv5bf7XiPy_xHPlP3A3K73m3QR2A HTTP/1.1" 200 8015
INFO 2016-06-21 15:52:25,937 module.py:812] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 200 5459
INFO 2016-06-21 15:52:25,941 module.py:812] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 200 5459
INFO 2016-06-21 15:52:25,942 module.py:812] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 200 5459
INFO 2016-06-21 15:52:26,183 module.py:812] default: "GET /_ah/api/discovery/v1/apis/library2/v2.0/rest HTTP/1.1" 200 3277
INFO 2016-06-21 15:52:26,203 module.py:812] default: "GET /_ah/api/discovery/v1/apis/library1/v1.0/rest HTTP/1.1" 200 3277
INFO 2016-06-21 15:52:26,210 module.py:812] default: "GET /_ah/api/discovery/v1/apis/library2/v1.0/rest HTTP/1.1" 200 3277
person
Dan Cornilescu
schedule
21.06.2016