|
1 | 1 | # Google Cloud Endpoints & App Engine Flexible Environment & PHP |
2 | 2 |
|
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. |
4 | 5 |
|
5 | | -This sample consists of two parts: |
| 6 | +The sample code lives in [a parent endpoints directory][1]. |
6 | 7 |
|
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 |
0 commit comments