Set Up Development Environment
Editor – Sublime Text
Python 2.7 – check your version by running python -V and if it’s not 2.7.
Git – download git from it’s official site.
SDK – download and install Google App Engine SDK for Python
https://cloud.google.com/appengine/downloads
def sumUp(n): total = 0 for x in range(n): total += x return total sumUp = timer.timedFunction(sumUp)
import endpoints from protorpc import message from protorpc import message_types from protorpc import remote REQUEST_CONTAINER = endpoints.ResourceContainer( message_types.VoidMessage, name=messages.StringField(1), ) package = 'Hello' class Hello(messages.Message): """String that stores a message.""" greeting = messages.StringField(1) @endpoints.api(name='helloworldendpoints', version='v1') class HelloWorldApi(remote.Service): """Helloworld API v1.""" @endpoints.method(message_types.VoidMessage, Hello, path = "sayHello", http_method='GET', name = "sayHello") def say_hello(self, request): return Hello(greeting="Hello World") @endpoints.method(REQUEST_CONTAINER, Hello, path = "sayHelloByName", http_method='GET', name = "sayHelloByName") def say_hello_by_name(self, request): greet = "Hello {}".format(request.name) return Hello(greeting=greet) APPLICATION = endpoints.api_server([HelloWorldApi])
Field Classes
https://cloud.google.com/appengine/docs/python/tools/protorpc/messages/fieldclasses
API Explore
https://developers.google.com/apis-explorer/#p/
translate api
{ "data": { "translations": [ { "translatedText": "Hallo Welt" }, { "translatedText": "Mein Name ist Jeff" } ] } }
from google.appengine.ext import ndb class Recipe(ndb.Model): name = StringProperty() ingredients = StringProperty(repeated=True) instructions = TextProperty() vegetarian = BooleanProperty() servings = IntegerProperty()