From 19fce9af95c6158efad21cbc8dcadc5147f49b70 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Wed, 27 Apr 2016 10:40:38 -0700 Subject: [PATCH] Adding endpoints multiapi sample. Change-Id: Iabb492a959c44b15a38c0a8e7f58223d99535f0b --- appengine/endpoints/{ => backend}/app.yaml | 0 appengine/endpoints/{ => backend}/main.py | 0 .../endpoints/{ => backend}/main_test.py | 0 appengine/endpoints/multiapi/app.yaml | 16 ++++++ appengine/endpoints/multiapi/main.py | 52 +++++++++++++++++++ appengine/endpoints/multiapi/main_test.py | 27 ++++++++++ 6 files changed, 95 insertions(+) rename appengine/endpoints/{ => backend}/app.yaml (100%) rename appengine/endpoints/{ => backend}/main.py (100%) rename appengine/endpoints/{ => backend}/main_test.py (100%) create mode 100644 appengine/endpoints/multiapi/app.yaml create mode 100644 appengine/endpoints/multiapi/main.py create mode 100644 appengine/endpoints/multiapi/main_test.py diff --git a/appengine/endpoints/app.yaml b/appengine/endpoints/backend/app.yaml similarity index 100% rename from appengine/endpoints/app.yaml rename to appengine/endpoints/backend/app.yaml diff --git a/appengine/endpoints/main.py b/appengine/endpoints/backend/main.py similarity index 100% rename from appengine/endpoints/main.py rename to appengine/endpoints/backend/main.py diff --git a/appengine/endpoints/main_test.py b/appengine/endpoints/backend/main_test.py similarity index 100% rename from appengine/endpoints/main_test.py rename to appengine/endpoints/backend/main_test.py diff --git a/appengine/endpoints/multiapi/app.yaml b/appengine/endpoints/multiapi/app.yaml new file mode 100644 index 000000000000..31030b73367e --- /dev/null +++ b/appengine/endpoints/multiapi/app.yaml @@ -0,0 +1,16 @@ +runtime: python27 +threadsafe: true +api_version: 1 + +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 + +libraries: +- name: pycrypto + version: 2.6 +- name: endpoints + version: 1.0 diff --git a/appengine/endpoints/multiapi/main.py b/appengine/endpoints/multiapi/main.py new file mode 100644 index 000000000000..e7884ebcf575 --- /dev/null +++ b/appengine/endpoints/multiapi/main.py @@ -0,0 +1,52 @@ +# Copyright 2016 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""This is a sample multi-class API implemented using Cloud Ednpoints""" + +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) + + +# [START multiclass] +api_collection = endpoints.api(name='library', version='v1.0') + + +@api_collection.api_class(resource_name='shelves') +class Shelves(remote.Service): + + @endpoints.method(Request, Response, path='list') + def list(self, request): + return Response() + + +@api_collection.api_class(resource_name='books', path='books') +class Books(remote.Service): + + @endpoints.method(Request, Response, path='bookmark') + def bookmark(self, request): + return Response() +# [END multiclass] + +# [START api_server] +api = endpoints.api_server([api_collection]) +# [END api_server] diff --git a/appengine/endpoints/multiapi/main_test.py b/appengine/endpoints/multiapi/main_test.py new file mode 100644 index 000000000000..a61548595ec6 --- /dev/null +++ b/appengine/endpoints/multiapi/main_test.py @@ -0,0 +1,27 @@ +# Copyright 2016 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import main + + +def test_shelves(testbed): + api = main.Shelves() + response = api.list(main.Request()) + assert response + + +def test_books(testbed): + api = main.Books() + response = api.bookmark(main.Request()) + assert response