YOUR_PROJECT_ID は実際の Google Cloud プロジェクト ID で置き換え、YOUR_SERVICE_VERSION は前の手順で取得したサービス構成 ID で置き換えます。これを app.yaml ファイルに追加してアプリケーションを再デプロイすると、Endpoints が API を管理するようになります。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2024-12-21 UTC。"],[[["\u003cp\u003eCloud Endpoints Frameworks provides API management features, including monitoring, logging, quotas, and a developer portal, similar to the Extensible Service Proxy (ESP) for Cloud Endpoints.\u003c/p\u003e\n"],["\u003cp\u003eTo manage an API with Endpoints, you must deploy an OpenAPI document (version 2.0) that describes the API, enabling functionalities such as logging, monitoring, and setting quotas.\u003c/p\u003e\n"],["\u003cp\u003eInstalling the Google Cloud CLI, along with the App Engine extension for Python and adding the Endpoints Frameworks Python library to your project, is necessary for configuring the development environment.\u003c/p\u003e\n"],["\u003cp\u003eGenerating an OpenAPI document with the framework tools, using commands such as \u003ccode\u003epython lib/endpoints/endpointscfg.py get_openapi_spec\u003c/code\u003e, allows for either single or multiple class API descriptions, deployable through the gcloud CLI.\u003c/p\u003e\n"],["\u003cp\u003eAfter deploying the OpenAPI document and redeploying the API, make sure to edit the \u003ccode\u003eapp.yaml\u003c/code\u003e file with the \u003ccode\u003eENDPOINTS_SERVICE_NAME\u003c/code\u003e and \u003ccode\u003eENDPOINTS_SERVICE_VERSION\u003c/code\u003e, to confirm that Endpoints manages your API, and then use gcloud commands to test the redeployment.\u003c/p\u003e\n"]]],[],null,["# Adding API management\n\nCloud Endpoints Frameworks provides API management features that are comparable to\nthe features that the\n[Extensible Service Proxy (ESP)](/endpoints/docs/frameworks/glossary#extensible_service_proxy)\nprovides for Cloud Endpoints. Endpoints Frameworks includes a\nbuilt-in\n[API gateway](https://en.wikipedia.org/wiki/API_management)\nthat intercepts all requests and performs any necessary checks, such as\nauthentication, before forwarding the request to the API backend. When the backend\nresponds, Endpoints Frameworks gathers and reports telemetry. You can\nview metrics for your API on the **Endpoints** \\\u003e **Services** page in the\nGoogle Cloud console.\n\nThe API management features available in Endpoints Frameworks include:\n\n- [Monitoring](/endpoints/docs/frameworks/monitoring-your-api)\n- [Logging](/endpoints/docs/frameworks/monitoring-your-api#logs)\n- [Quotas](/endpoints/docs/openapi/quotas-overview)\n- [Developer portal](/endpoints/docs/openapi/dev-portal-overview)\n\nFor your API to be managed by Endpoints, you must deploy\nan OpenAPI document that describes your API using version 2.0 of the\n[OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md).\nThis page describes how to generate and deploy an OpenAPI document that\nenables Endpoints to manage your API.\n\nIf you don't add API management, your API still serves requests, but your\nAPI doesn't appear on the **Endpoints** \\\u003e **Services** page in the\nGoogle Cloud console, and the functionality provided by\nEndpoints, such as logging, monitoring, and setting quotas, isn't\navailable.\n\nInstalling and configuring required software\n--------------------------------------------\n\nIf you haven't already done so, install and configure the Google Cloud CLI for\nPython, and add the Endpoints Frameworks Python library to your API\nproject directory so it is uploaded with the API code upon deployment\n\n### Install and configure the gcloud CLI for Python\n\n1. Install and initialize gcloud CLI:\n\n [Download and install gcloud CLI](/sdk/docs)\n2. Install the `gcloud` component that includes the\n App Engine extension for Python:\n\n gcloud components install app-engine-python\n\n3. Update the gcloud CLI:\n\n gcloud components update\n\n4. Make sure that the gcloud CLI is authorized to access your data and\n services on Google Cloud:\n\n gcloud auth login\n\n A new browser tab opens and you are prompted to choose an account.\n5. Set the default project to your project ID. Replace\n \u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e with your Google Cloud project ID.\n\n ```\n gcloud config set project YOUR_PROJECT_ID\n ```\n6. For Linux, set the `ENDPOINTS_GAE_SDK` environment variable to the path of\n your App Engine SDK folder:\n\n ```\n PATH_TO_CLOUD_SDK/platform/google_appengine\n ```\n\n Replace \u003cvar translate=\"no\"\u003ePATH_TO_CLOUD_SDK\u003c/var\u003e with the output of\n the following command: \n\n gcloud info --format=\"value(installation.sdk_root)\"\n\n### Add the Endpoints Frameworks Python library\n\n1. Be sure you can compile C extensions for Python.\n\n - Windows: Microsoft Visual C++ 9.0 or greater is required. You can\n download the Microsoft Visual C++ Compiler for Python 2.7 from the\n [Microsoft download center](http://aka.ms/vcpython27)\n\n - Other operating systems: Depending on your operating system, you may\n need to install compiler tools (sometimes in a package called\n `build-essential`) and/or the Python development headers (sometimes in a\n package called `python-dev`).\n\n2. Change directory to your API's main directory.\n\n3. Make a `/lib` subdirectory in the API's main directory:\n\n mkdir lib\n\n4. Install the library:\n\n pip install -t lib google-endpoints --ignore-installed\n\nGenerate the OpenAPI document\n-----------------------------\n\nFrom the API's main directory, generate an OpenAPI document by using the framework\ntools. For example: \n\n### Single Class\n\nIn the following command, replace \u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e with\nyour Google Cloud project ID. \n\n```\npython lib/endpoints/endpointscfg.py get_openapi_spec main.EchoApi \\\n --hostname YOUR_PROJECT_ID.appspot.com\n```\n\nIgnore the warnings that are displayed.\n\n### Multiple Classes\n\nYou can list multiple classes on the command line. Endpoints\ngenerates an OpenAPI document for each API name/version combination.\n\nIf you want to deploy multiple API classes with different API names as part\nof a single service, you must also add the `--x-google-api-name` flag.\nEnabling this flag adds extra restrictions on your API names. Specifically,\nthe names must match the regular expression `[a-z][a-z0-9]{0,39}`; that is,\nthe name must consist of 1-40 characters, which can all be either lowercase\nalphabetical characters or numbers, except that the first character must not\nbe a number. For example:\n\nIn the following command, replace \u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e\nwith your Google Cloud project ID. \n\n```\npython lib/endpoints/endpointscfg.py get_openapi_spec main.FooApi main.BarApi \\\n --hostname YOUR_PROJECT_ID.appspot.com \\\n --x-google-api-name\n```\n\nIgnore the warnings that are displayed.\n\nEndpoints uses the text that you specify in the `hostname`\nargument as the service name. When you deploy the API to App Engine,\na DNS entry with a name in the format\n\u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e`.appspot.com` is created\nautomatically.\n\nDeploy the OpenAPI document\n---------------------------\n\n### Single Class\n\n gcloud endpoints services deploy echov1openapi.json\n\n### Multiple Classes\n\nIf you have multiple OpenAPI documents, list them all on the command line.\nFor example: \n\n gcloud endpoints services deploy foov1openapi.json barv1openapi.json\n\nThis first time you deploy your OpenAPI document (or documents), a new\nEndpoints service is created with the name\n\u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e`.appspot.com`.\n\nOn successful completion, a line similar to the following displays the service\nconfiguration ID and the service name: \n\n```\nService Configuration 2017-02-13r0 uploaded for service example-project-12345.appspot.com\n```\n\nIn the example above, \u003cvar translate=\"no\"\u003e2017-02-13r0\u003c/var\u003e is the service configuration\nID. The service configuration ID consists of a date stamp followed by a\nrevision number. If you deploy your OpenAPI document again, the revision\nnumber is incremented in the service configuration ID.\n\nIf you need to display the service configuration ID again, run the following\ncommand, but replace \u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e with the project ID\nof your Google Cloud project: \n\n```\ngcloud endpoints configs list --service=YOUR_PROJECT_ID.appspot.com\n```\n\nYou can create your own OpenAPI document and deploy it, rather than\nusing a generated one. Simply replace `echov1openapi.json` above with the\npath to your OpenAPI document. For more information on writing an OpenAPI\ndocument, see\n[OpenAPI overview](/endpoints/docs/openapi/openapi-overview).\n\nRedeploy your API and test\n--------------------------\n\n1. Edit your project's file `app.yaml` and add an `env_variables` section as\n follows:\n\n ```\n env_variables:\n ENDPOINTS_SERVICE_NAME: YOUR_PROJECT_ID.appspot.com\n ENDPOINTS_SERVICE_VERSION: YOUR_SERVICE_VERSION\n ```\n\n Replace \u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e with your\n Google Cloud project ID, and \u003cvar translate=\"no\"\u003eYOUR_SERVICE_VERSION\u003c/var\u003e\n with your service configuration ID from the\n previous section. With this addition to the `app.yaml` file,\n Endpoints manages your API after you\n redeploy your application.\n2. Redeploy your application:\n\n gcloud app deploy\n\n3. Wait a few moments for the deployment to succeed, ignoring the warning\n messages. When the deployment completes, a message similar to the\n following is displayed:\n\n File upload done.\n Updating service [default]...done.\n\n4. Test for a successful redeployment, for example, using curl:\n\n ```\n curl --request POST \\\n --header \"Content-Type: application/json\" \\\n --data '{\"content\":\"echo\"}' \\\n https://YOUR_PROJECT_ID.appspot.com/_ah/api/echo/v1/echo?n=2\n ```\n\n Replace `echo` with the name of your API.\n\n The results should display something similar to: \n\n {\n \"content\": \"echo echo\"\n }\n\n5. Make some additional requests to your API.\n\n6. To\n [view your API metrics](/endpoints/docs/frameworks/monitoring-your-api),\n open the **Endpoints** \\\u003e **Services** page in the Google Cloud console for your project: \n\n\n [Go to the Endpoints Services page](https://console.cloud.google.com/endpoints)\n\n \u003cbr /\u003e"]]