Cloud Endpoints Frameworks는 Extensible Service Proxy(ESP)가 Cloud Endpoints에 제공하는 기능과 비슷한 API 관리 기능을 제공합니다. Endpoints Frameworks에는 요청을 API 백엔드로 전달하기 전에 모든 요청을 가로채고 필요한 검사(예: 인증)를 수행하는 기본 제공 API 게이트웨이가 포함되어 있습니다. 백엔드가 응답하면 Endpoints Frameworks는 원격 분석 데이터를 수집하고 보고합니다. API의 측정항목은 Google Cloud Console의 Endpoints > 서비스 페이지에서 확인할 수 있습니다.
Endpoints를 통해 API를 관리하려면 OpenAPI 사양 버전 2.0을 사용하여 API를 설명하는 OpenAPI 문서를 배포해야 합니다.
이 페이지에서는 API를 관리하도록 Endpoints를 사용 설정하는 OpenAPI 문서를 생성하고 배포하는 방법을 설명합니다.
API 관리를 추가하지 않으면 API는 계속해서 요청을 처리하지만 Google Cloud Console의 Endpoints > 서비스 페이지에 API가 표시되지 않고 Endpoints에서 제공하는 기능(예: 로깅, 모니터링, 할당량 설정)을 사용할 수 없습니다.
필수 소프트웨어 설치 및 구성
아직 하지 않은 경우 Python용 Google Cloud CLI를 설치 및 구성하고 Endpoints Frameworks Python 라이브러리를 API 프로젝트 디렉터리에 추가하여 배포 시 API 코드와 함께 업로드되도록 합니다.
명령줄에 여러 클래스를 나열할 수 있습니다. Endpoints는 각 API 이름/버전 조합별로 OpenAPI 문서를 생성합니다.
API 이름이 서로 다른 여러 API 클래스를 단일 서비스의 일부로 배포하려면 --x-google-api-name 플래그도 추가해야 합니다.
이 플래그를 사용 설정하면 API 이름에 제한이 추가됩니다. 특히 이름은 정규 표현식 [a-z][a-z0-9]{0,39}와 일치해야 합니다. 즉, 이름이 알파벳 소문자 또는 숫자로 구성된 1~40자 사이여야 하고, 이름의 첫 글자는 숫자가 아니어야 합니다. 예를 들면 다음과 같습니다.
다음 명령어에서 YOUR_PROJECT_ID를 Google Cloud 프로젝트 ID로 바꿉니다.
[[["이해하기 쉬움","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"]]