Skip to content

Commit 1c1c7bc

Browse files
author
Jon Wayne Parrott
committed
Adding endpoints multiapi sample. (#289)
Change-Id: Iabb492a959c44b15a38c0a8e7f58223d99535f0b
1 parent 2f298d7 commit 1c1c7bc

File tree

6 files changed

+95
-0
lines changed

6 files changed

+95
-0
lines changed
File renamed without changes.
File renamed without changes.

appengine/endpoints/multiapi/app.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
runtime: python27
2+
threadsafe: true
3+
api_version: 1
4+
5+
handlers:
6+
# The endpoints handler must be mapped to /_ah/spi.
7+
# Apps send requests to /_ah/api, but the endpoints service handles mapping
8+
# those requests to /_ah/spi.
9+
- url: /_ah/spi/.*
10+
script: main.api
11+
12+
libraries:
13+
- name: pycrypto
14+
version: 2.6
15+
- name: endpoints
16+
version: 1.0

appengine/endpoints/multiapi/main.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""This is a sample multi-class API implemented using Cloud Ednpoints"""
16+
17+
import endpoints
18+
from protorpc import messages
19+
from protorpc import remote
20+
21+
22+
class Request(messages.Message):
23+
message = messages.StringField(1)
24+
25+
26+
class Response(messages.Message):
27+
message = messages.StringField(1)
28+
29+
30+
# [START multiclass]
31+
api_collection = endpoints.api(name='library', version='v1.0')
32+
33+
34+
@api_collection.api_class(resource_name='shelves')
35+
class Shelves(remote.Service):
36+
37+
@endpoints.method(Request, Response, path='list')
38+
def list(self, request):
39+
return Response()
40+
41+
42+
@api_collection.api_class(resource_name='books', path='books')
43+
class Books(remote.Service):
44+
45+
@endpoints.method(Request, Response, path='bookmark')
46+
def bookmark(self, request):
47+
return Response()
48+
# [END multiclass]
49+
50+
# [START api_server]
51+
api = endpoints.api_server([api_collection])
52+
# [END api_server]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import main
16+
17+
18+
def test_shelves(testbed):
19+
api = main.Shelves()
20+
response = api.list(main.Request())
21+
assert response
22+
23+
24+
def test_books(testbed):
25+
api = main.Books()
26+
response = api.bookmark(main.Request())
27+
assert response

0 commit comments

Comments
 (0)