In the following instructions, we describe using a separate
module for the API server. However, it's not a
requirement; you could just add the required endpoints.api_server
code shown below to the module where you define your API. If you are defining
only a single API, you may want to define the API server in the same file
where you define your API because it doesn't need to import any other classes.
If you are defining multiple APIs (remote.Service subclasses) that
are defined in multiple files, it might be preferable to have a separate file
for your API Server in order to import all these class files.
You must define an API server that uses the API or APIs you have created. To do this,
- Create a separate module, for example,
services.py(you can use any name you want). The following sample shows what you would need to add to this file if you were exposing two classes (two APIs) in your endpoint:from google.appengine.ext import endpoints import your_api import your_other_api application = endpoints.api_server([your_api.YourApi, your_other_api.YourOtherApi], restricted=False)where
your_apiandyour_other_apiare the names of the modules containing the API classes you are exposing, andYourApiandYourOtherApiare the API class names. - In your
app.yamlfile, map the API server you just created to the endpoints location as follows:handlers: # Endpoints handler - url: /_ah/spi/.* script: services.application
where
servicesis the file name you used for your API server module. Notice that the endpoints path is always/_ah/spirelative to the application.