Implementing API endpoints

As we already mentioned, our REST API will be integrated with the existing App Engine application without altering its behavior, so we need to specify a new WSGI application that will handle the URLs we map to the API endpoints. Let's start with the app.yaml file, where we add the following code:

handlers:
- url: /static
  static_dir: static

- url: /_ah/spi/.*
  script: notes_api.app

- url: .*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.2"

- name: jinja2
  version: latest

- name: endpoints
  version: 1.0

The regular expression that matches API URLs is actually /_ah/spi/.*. Even if we perform requests to an URL such as https://example.com/_ah/api/v1/an-endpoint, Cloud Endpoints will take care of the proper redirects. ...

Get Python for Google App Engine now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.