Skip to content

Commit fddf5e6

Browse files
author
Jon Wayne Parrott
committed
Merge pull request #268 from GoogleCloudPlatform/remote-api
Adding remote api sample
2 parents 176ec8c + 7beb944 commit fddf5e6

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

appengine/remote_api/app.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
runtime: python27
2+
api_version: 1
3+
threadsafe: true
4+
5+
builtins:
6+
- remote_api: on

appengine/remote_api/client.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
"""Sample app that uses the Google App Engine Remote API to make calls to the
16+
live App Engine APIs."""
17+
18+
# [START all]
19+
20+
import argparse
21+
22+
try:
23+
import dev_appserver
24+
dev_appserver.fix_sys_path()
25+
except ImportError:
26+
print('Please make sure the App Engine SDK is in your PYTHONPATH.')
27+
raise
28+
29+
from google.appengine.ext import ndb
30+
from google.appengine.ext.remote_api import remote_api_stub
31+
32+
33+
def main(project_id):
34+
remote_api_stub.ConfigureRemoteApiForOAuth(
35+
'{}.appspot.com'.format(project_id),
36+
'/_ah/remote_api')
37+
38+
# List the first 10 keys in the datastore.
39+
keys = ndb.Query().fetch(10, keys_only=True)
40+
41+
for key in keys:
42+
print(key)
43+
44+
45+
if __name__ == '__main__':
46+
parser = argparse.ArgumentParser(
47+
description=__doc__,
48+
formatter_class=argparse.RawDescriptionHelpFormatter)
49+
parser.add_argument('project_id', help='Your Project ID.')
50+
51+
args = parser.parse_args()
52+
53+
main(args.project_id)
54+
# [END all]

0 commit comments

Comments
 (0)