Skip to content

Commit 002c3ca

Browse files
committed
makes endpoints samples generic and provides GKE deployment
1 parent 41db8e8 commit 002c3ca

File tree

19 files changed

+176
-120
lines changed

19 files changed

+176
-120
lines changed

appengine/flexible/endpoints/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 4 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,8 @@
11
# Google Cloud Endpoints & App Engine Flexible Environment & PHP
22

3-
This sample demonstrates how to use Google Cloud Endpoints on Google App Engine Flexible Environment using PHP.
3+
This sample demonstrates how to use Google Cloud Endpoints on Google App Engine
4+
Flexible Environment using PHP.
45

5-
This sample consists of two parts:
6+
The sample code lives in [a parent endpoints directory][1].
67

7-
1. The backend
8-
2. The clients
9-
10-
## Running locally
11-
12-
### Running the backend
13-
14-
For more info on running Flexible applications locally, see [the getting started documentation](https://cloud.google.com/php/getting-started/hello-world).
15-
16-
Install all the dependencies:
17-
18-
$ composer install
19-
20-
Run the application:
21-
22-
$ php -S localhost:8080
23-
24-
### Using the echo client
25-
26-
With the app running locally, you can execute the simple echo client using:
27-
28-
$ php endpoints.php make-request http://localhost:8080 APIKEY
29-
30-
The `APIKEY` can be any string as the local endpoint proxy doesn't need authentication.
31-
32-
## Deploying to Google App Engine
33-
34-
Open the `swagger.yaml` file and in the `host` property, replace
35-
`YOUR-PROJECT-ID` with your project's ID.
36-
37-
Then, deploy the sample using `gcloud`:
38-
39-
gcloud beta app deploy
40-
41-
> **IMPORTANT** be sure to use the gcloud `beta` command when deploying, otherwise
42-
endpoints will not take affect, and you will get a `502`.
43-
44-
Once deployed, you can access the application at https://YOUR-PROJECT-ID.appspot.com/
45-
or run the command `gcloud app browse`.
46-
47-
### Using the echo client
48-
49-
With the project deployed, you'll need to create an API key to access the API.
50-
51-
1. Open the Credentials page of the API Manager in the [Cloud Console](https://console.cloud.google.com/apis/credentials).
52-
2. Click 'Create credentials'.
53-
3. Select 'API Key'.
54-
4. Choose 'Server Key'
55-
56-
With the API key, you can use the echo client to access the API:
57-
58-
$ php endpoints.php make-request https://YOUR-PROJECT-ID.appspot.com YOUR-API-KEY
59-
60-
### Using the JWT client.
61-
62-
The JWT client demonstrates how to use service accounts to authenticate to endpoints. To use the client, you'll need both an API key (as described in the echo client section) and a service account. To create a service account:
63-
64-
1. Open the Credentials page of the API Manager in the [Cloud Console](https://console.cloud.google.com/apis/credentials).
65-
2. Click 'Create credentials'.
66-
3. Select 'Service account key'.
67-
4. In the 'Select service account' dropdown, select 'Create new service account'.
68-
5. Choose 'JSON' for the key type.
69-
70-
To use the service account for authentication:
71-
72-
1. Update the `google_jwt`'s `x-jwks_uri` in `swagger.yaml` with your service account's email address.
73-
2. Redeploy your application.
74-
75-
Now you can use the JWT client to make requests to the API:
76-
77-
$ php endpoints.php make-request https://YOUR-PROJECT-ID.appspot.com YOUR-API-KEY /path/to/service-account.json
78-
79-
### Using the ID Token client.
80-
81-
The ID Token client demonstrates how to use user credentials to authenticate to endpoints. To use the client, you'll need both an API key (as described in the echo client section) and a OAuth2 client ID. To create a client ID:
82-
83-
1. Open the Credentials page of the API Manager in the [Cloud Console](https://console.cloud.google.com/apis/credentials).
84-
2. Click 'Create credentials'.
85-
3. Select 'OAuth client ID'.
86-
4. Choose 'Other' for the application type.
87-
88-
To use the client ID for authentication:
89-
90-
1. Update the `/auth/info/googleidtoken`'s `audiences` in `swagger.yaml` with your client ID.
91-
2. Redeploy your application.
92-
93-
Now you can use the client ID to make requests to the API:
94-
95-
$ php endpoints.php make-request https://YOUR-PROJECT-ID.appspot.com YOUR-API-KEY /path/to/client-secrets.json
96-
97-
## Viewing the Endpoints graphs
98-
99-
By using Endpoints, you get access to several metrics that are displayed graphically in the Cloud Console.
100-
101-
To view the Endpoints graphs:
102-
103-
1. Go to the [Endpoints section in Cloud Console](https://console.cloud.google.com/endpoints) of the project you deployed your API to.
104-
2. Click on your API to view more detailed information about the metrics collected.
105-
106-
## Swagger UI
107-
108-
The Swagger UI is an open source Swagger project that allows you to explore your API through a UI. Find out more about it on the [Swagger site](http://swagger.io/swagger-ui/).
8+
[1]: ../../../endpoints/getting-started

appengine/flexible/endpoints/test/bootstrap.php

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM gcr.io/google_appengine/php
File renamed without changes.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Google Cloud Endpoints & PHP
2+
3+
This sample demonstrates how to use Google Cloud Endpoints using PHP.
4+
5+
For a complete walkthrough showing how to run this sample in different
6+
environments, see the
7+
[Google Cloud Endpoints Quickstarts](https://cloud.google.com/endpoints/docs/quickstarts).
8+
9+
This sample consists of two parts:
10+
11+
1. The backend
12+
2. The clients
13+
14+
## Running locally
15+
16+
### Running the backend
17+
18+
Install all the dependencies:
19+
20+
$ composer install
21+
22+
Run the application:
23+
24+
$ php -S localhost:8080
25+
26+
### Using the echo client
27+
28+
With the app running locally, you can execute the simple echo client using:
29+
30+
$ php endpoints.php make-request http://localhost:8080 APIKEY
31+
32+
The `APIKEY` can be any string as the local endpoint proxy doesn't need authentication.
33+
34+
## Deploying to Production
35+
36+
See the
37+
[Google Cloud Endpoints Quickstarts](https://cloud.google.com/endpoints/docs/quickstarts).
38+
39+
### Using the echo client
40+
41+
With the project deployed, you'll need to create an API key to access the API.
42+
43+
1. Open the Credentials page of the API Manager in the [Cloud Console](https://console.cloud.google.com/apis/credentials).
44+
2. Click 'Create credentials'.
45+
3. Select 'API Key'.
46+
4. Choose 'Server Key'
47+
48+
With the API key, you can use the echo client to access the API:
49+
50+
$ php endpoints.php make-request https://YOUR-PROJECT-ID.appspot.com YOUR-API-KEY
51+
52+
### Using the JWT client.
53+
54+
The JWT client demonstrates how to use service accounts to authenticate to endpoints. To use the client, you'll need both an API key (as described in the echo client section) and a service account. To create a service account:
55+
56+
1. Open the Credentials page of the API Manager in the [Cloud Console](https://console.cloud.google.com/apis/credentials).
57+
2. Click 'Create credentials'.
58+
3. Select 'Service account key'.
59+
4. In the 'Select service account' dropdown, select 'Create new service account'.
60+
5. Choose 'JSON' for the key type.
61+
62+
To use the service account for authentication:
63+
64+
1. Update the `google_jwt`'s `x-jwks_uri` in `swagger.yaml` with your service account's email address.
65+
2. Redeploy your application.
66+
67+
Now you can use the JWT client to make requests to the API:
68+
69+
$ php endpoints.php make-request https://YOUR-PROJECT-ID.appspot.com YOUR-API-KEY /path/to/service-account.json
70+
71+
### Using the ID Token client.
72+
73+
The ID Token client demonstrates how to use user credentials to authenticate to endpoints. To use the client, you'll need both an API key (as described in the echo client section) and a OAuth2 client ID. To create a client ID:
74+
75+
1. Open the Credentials page of the API Manager in the [Cloud Console](https://console.cloud.google.com/apis/credentials).
76+
2. Click 'Create credentials'.
77+
3. Select 'OAuth client ID'.
78+
4. Choose 'Other' for the application type.
79+
80+
To use the client ID for authentication:
81+
82+
1. Update the `/auth/info/googleidtoken`'s `audiences` in `swagger.yaml` with your client ID.
83+
2. Redeploy your application.
84+
85+
Now you can use the client ID to make requests to the API:
86+
87+
$ php endpoints.php make-request https://YOUR-PROJECT-ID.appspot.com YOUR-API-KEY /path/to/client-secrets.json
88+
89+
## Viewing the Endpoints graphs
90+
91+
By using Endpoints, you get access to several metrics that are displayed graphically in the Cloud Console.
92+
93+
To view the Endpoints graphs:
94+
95+
1. Go to the [Endpoints section in Cloud Console](https://console.cloud.google.com/endpoints) of the project you deployed your API to.
96+
2. Click on your API to view more detailed information about the metrics collected.
97+
98+
## Swagger UI
99+
100+
The Swagger UI is an open source Swagger project that allows you to explore your API through a UI. Find out more about it on the [Swagger site](http://swagger.io/swagger-ui/).
File renamed without changes.

appengine/flexible/endpoints/composer.lock renamed to endpoints/getting-started/composer.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)