This sample demonstrates how to use Google Cloud Endpoints Frameworks using Java on App Engine Standard.
You must add the project ID obtained when you created your project to the
sample's pom.xml before you can deploy the code.
To add the project ID:
-
Edit the file
pom.xml. -
For
<endpoints.project.id>, replace the valueYOUR_PROJECT_IDwith your project ID. -
Edit the file
src/main/java/com/example/echo/Echo.java. -
Replace the value
YOUR-PROJECT-IDwith your project ID. -
Save your changes.
To build the project:
mvn clean package
To generate the required configuration file openapi.json:
mvn exec:java -DGetSwaggerDoc
To deploy the sample API:
-
Invoke the
gcloudcommand to deploy the API configuration file:gcloud service-management deploy openapi.json -
Deploy the API implementation code by invoking:
mvn appengine:deployThe first time you upload a sample app, you may be prompted to authorize the deployment. Follow the prompts: when you are presented with a browser window containing a code, copy it to the terminal window.
-
Wait for the upload to finish.
After you deploy the API and its configuration file, you can send requests to the API.
To send a request to the API, from a command line, invoke the following cURL
command:
curl \
-H "Content-Type: application/json" \
-X POST \
-d '{"message":"echo"}' \
https://$PROJECT_ID.appspot.com/_ah/api/echo/v1/echo
You will get a 200 response with the following data:
{
"message": "echo"
}