This sample demonstrates how to use Google Cloud Endpoints for a Connexion based Python API hosted on Google App Engine Flexible environment.
It's basically the "curated" mix of three other repos:
- Google Cloud Endpoints Client Samples.
- Google Cloud Endpoints Python Getting Started.
- Connexion Example REST Service.
This sample consists of two parts:
- The backend code and configuration
- A frontend application to showcase web clients authentication options: Firebase Auth and Google Accounts
The first thing to do is create a project in the Google Cloud console. Take note of your project ID and replace all the [PROJECT_ID]
placeholders with your actual project ID, that you assigned while creating the project.
In order to use Firebase Auth you need to also create a Project in the Firebase Console follow the instructions here in this sample I used the same project ID for both. Paste the initialization code snippet into /frontend/firebase.html
Also make sure to generate an OAuth client ID follow the instructions here and replace the placeholder [GOOGLE_OAUTH_CLIENT_ID]
inside /frontend/google.html
and in /backend/openapi.yaml
with it.
$ cd backend
Install all the dependencies:
$ virtualenv env
$ source env/bin/activate
$ pip install -r requirements.txt
Run the application:
$ python app.py
$ cd frontend
To launch the frontend you can install and use serve
$ npm install -g serve
$ serve .
Deploy the Open API spec file to Google Cloud Endpoints services management using the Gcloud CLI
$ gcloud endpoints services deploy openapi.yaml
After the deployment finish, take note of the assigned version and replace the [API_VERSION]
placeholder inside of /backend/app.yaml
.
$ gcloud app deploy
With that you are ready to access the API using this URL: https://[PROJECT_ID].appspot.com
Go to the frontend folder
$ cd frontend
Install Firebase command line tools and authenticate and setup the project ID
$ npm install -g firebase-tools
$ firebase login
$ firebase use [PROJECT_ID]
With that you are ready to deploy
$ firebase deploy
With that you are ready to access the app in this URL: https://[PROJECT_ID].firebaseapp.com