Creating an API server

You must define an API server that uses the API or APIs you have created. To define an API server:

  1. Create a Python module, for example main.py, and create an endpoints.api_server object at the top-level:

    api = endpoints.api_server([EchoApi])

    Note that you provide a list of remote.Service objects to the API server. If you have an API that is is implemented in several classes, then your Service object is a collection of classes as described in Creating an API Implemented with Multiple Classes.

    A separate module is not required when describing an API. If you are defining multiple APIs (remote.Service subclasses) that are defined in multiple files, then it is recommended to have a separate module for your API server in order to import all these class files.

    Alternatively, add the required endpoints.api_server code to the module where you define your API. If you are defining only a single API, define the API server in the API definition file because it doesn't need to import any other classes.

  2. In your app.yaml file, map the API server you just created to the endpoints location as follows:

    handlers:
    # The endpoints handler must be mapped to /_ah/api.
    - url: /_ah/api/.*
      script: main.api
    
    

    where main is the Python module you used for your API server module.

Serving your API from a different path

Optional: To serve your API from a different path, for example /api/:

  1. Modify the decorator:

    @endpoints.api(name='echo', version='v1', base_path='/api/')
    
  2. Change the handlers section in app.yaml:

    handlers:
    - url: /api/.*
      script: main.api
    
Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Endpoints Frameworks for App Engine