내가 만든 하나 이상의 API를 사용하는 웹 서버를 정의해야 합니다.
Python용 Cloud Endpoints 프레임워크는 표준 웹 서버 게이트웨이 인터페이스(WSGI)를 구현하여 API에 대한 요청을 코드의 메서드로 라우팅합니다.
App Engine에서 실행되는 모든 애플리케이션과 마찬가지로 App Engine 앱의 설정을 구성하는 app.yaml이라는 파일을 만들어야 합니다. 웹 서버를 정의하려면 app.yaml 파일을 변경합니다.
웹 서버를 정의하려면 다음 안내를 따르세요.
Python 모듈(예: main.py)을 만들고 최상위 수준에 endpoints.api_server 객체를 만듭니다.
api=endpoints.api_server([EchoApi])
api = endpoints.api_server([EchoApi]) 코드는 API 요청을 EchoAPI 클래스의 메서드로 라우팅하는 WSGI 애플리케이션을 만듭니다.
remote.Service 객체(API를 만들 때 정의함)의 목록을 endpoints.api_server에 제공할 수 있습니다. 여러 클래스에서 구현되는 API가 있는 경우 remote.Service 객체는 여러 클래스로 구현된 API 만들기에서 설명하는 클래스 컬렉션입니다.
endpoints.api_server 객체를 위한 별도의 모듈을 만들지 여부는 단일 API를 만들었는지 여러 API를 만들었는지에 따라 결정됩니다.
여러 파일에 정의된 여러 API를 만든 경우(여러 remote.Service 서브클래스 사용) 모든 클래스 파일을 가져올 수 있도록 endpoints.api_server 객체를 위한 별도의 모듈을 만드는 것이 좋습니다.
API를 하나만 만든 경우에는 다른 클래스를 가져올 필요가 없으므로 필요한 endpoints.api_server 코드를 API를 정의하는 모듈에 추가하면 됩니다.
app.yaml 파일에서 방금 만든 웹 서버를 다음과 같이 Cloud Endpoints 위치에 매핑합니다.
handlers:# The endpoints handler must be mapped to /_ah/api.-url:/_ah/api/.*script:main.api
여기서 main은 endpoints.api_server 객체를 정의한 Python 모듈입니다.
Python용 Endpoints Frameworks는 표준 Python 로깅 모듈을 사용하여 애플리케이션의 상태 및 요청 수명 주기에 대한 정보를 로깅합니다. App Engine 로그에 대한 자세한 내용 및 확인 방법은 App Engine 문서의 애플리케이션 로그 읽기 및 쓰기를 참조하세요.
Python 로깅 모듈은 사전 정의된 로그 수준을 제공합니다. 로그 수준을 심각도 순으로 나열하면 다음과 같습니다.
로그 수준
설명
DEBUG
상세한 로그를 제공합니다. 일반적으로 문제해결이 필요한 경우에만 이 수준을 설정합니다.
INFO
Endpoints Frameworks의 기본 로그 수준입니다. 애플리케이션의 진행 상황을 개략적으로 추적할 수 있습니다.
WARNING
예상치 못한 문제의 발생을 경고하지만 애플리케이션은 복구되어 계속 정상적으로 실행됩니다.
ERROR
일부 기능 손실을 야기하는 문제의 발생을 경고하지만 애플리케이션은 계속 실행됩니다.
CRITICAL
애플리케이션 중지를 야기하는 심각한 오류나 이벤트의 발생을 경고합니다.
로거는 점으로 구분된 계층 구조로 존재합니다. 예를 들어 endpoints.api_config 로거는 endpoints 로거의 하위 항목입니다. 이러한 계층 구조를 통해 생성하거나 차단할 로그를 정밀하게 제어할 수 있습니다. 일반적으로는 Endpoints 프레임워크의 루트 로거 2개(endpoints 및 endpoints_management)만 변경합니다.
Endpoints 프레임워크에 DEBUG 로깅 사용 설정
로그 리더의 과부하를 방지하기 위해 Endpoints 프레임워크는 로거가 INFO 로그 수준 이상의 로그 항목만 기록하도록 설정합니다. Endpoints 프레임워크를 모듈로 가져온 후에는 다음과 같이 언제든지 로그 수준을 변경할 수 있습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eA web server must be defined within the \u003ccode\u003eapp.yaml\u003c/code\u003e file to route requests to your API's methods using the Web Server Gateway Interface (WSGI).\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eendpoints.api_server\u003c/code\u003e object, created in a Python module like \u003ccode\u003emain.py\u003c/code\u003e, functions as a WSGI application that routes API requests, with the option to include multiple \u003ccode\u003eremote.Service\u003c/code\u003e objects if you have a multi-class API.\u003c/p\u003e\n"],["\u003cp\u003eIn the \u003ccode\u003eapp.yaml\u003c/code\u003e file, you must map the web server to the Cloud Endpoints location, by setting the url handler to \u003ccode\u003e/_ah/api/.*\u003c/code\u003e or a different path if configured, and link the script to the module where \u003ccode\u003eendpoints.api_server\u003c/code\u003e was defined.\u003c/p\u003e\n"],["\u003cp\u003eEndpoints Frameworks for Python employs the standard Python logging module, with levels ranging from \u003ccode\u003eDEBUG\u003c/code\u003e to \u003ccode\u003eCRITICAL\u003c/code\u003e, defaulting to \u003ccode\u003eINFO\u003c/code\u003e, and can be modified using the \u003ccode\u003esetLevel\u003c/code\u003e method for loggers like \u003ccode\u003eendpoints\u003c/code\u003e and \u003ccode\u003eendpoints_management\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Creating a web server\n\nYou must define a web server that uses the\n[API or APIs you have created](/endpoints/docs/frameworks/python/create_api).\nCloud Endpoints Frameworks for Python implements the standard\n[Web Server Gateway Interface](https://wsgi.readthedocs.io/)\n(WSGI) to route requests to your API to the methods in your code.\n\nAs with every application that runs on App Engine, you must create a file\ncalled [`app.yaml`](/appengine/docs/standard/python/config/appref) in which you\nconfigure your App Engine app's settings. To define the web server,\nyou make changes to your `app.yaml` file.\n\nTo define a web server:\n\n1. Create a Python module, for example `main.py`, and create an\n `endpoints.api_server` object at the top-level:\n\n api = endpoints.api_server([EchoApi])\n\n The code `api = endpoints.api_server([EchoApi])` creates a WSGI application\n that routes API requests to the methods in the `EchoAPI` class.\n\n You can provide a list of `remote.Service` objects (which you defined when\n you [created your API](/endpoints/docs/frameworks/python/create_api)) to\n `endpoints.api_server`. If you have an API that is implemented in several\n classes, then your `remote.Service` object is a collection of classes as\n described in [Creating an API implemented with multiple\n classes](/endpoints/docs/frameworks/python/create-multi-class-api).\n\n Whether you create a separate module for the `endpoints.api_server` object\n depends on whether you created a single API or multiple APIs.\n - If you created multiple APIs (using multiple `remote.Service`\n subclasses) that are defined in multiple files, then we recommend that\n you create a separate module for the `endpoints.api_server` object so\n that you can import all the class files.\n\n - If you created a single API, you can add the required\n `endpoints.api_server` code to the module where you define your API\n because you don't need to import any other classes.\n\n | **Warning:** if your code doesn't call `endpoints.api_server`, you will get a deployment failure when you try to deploy.\n2. In your `app.yaml` file, map the web server you just created to\n the Cloud Endpoints location as follows:\n\n handlers:\n # The endpoints handler must be mapped to /_ah/api.\n - url: /_ah/api/.*\n script: main.api\n\n where `main` is the Python module you in which you defined the\n `endpoints.api_server` object.\n\nServing your API from a different path\n--------------------------------------\n\nOptional: To serve your API from a different path, for example `/api/`:\n\n1. Modify the decorator:\n\n @endpoints.api(name='echo', version='v1', base_path='/api/')\n\n2. Change the `handlers` section in the `app.yaml` file:\n\n handlers:\n - url: /api/.*\n script: main.api\n\nLogging in Endpoints Frameworks for Python\n------------------------------------------\n\nEndpoints Frameworks for Python uses the\n[standard Python logging module](https://docs.python.org/2/library/logging.html)\nto log information about\nthe application's status and request lifecycle. To learn more about\nApp Engine logs and how to view them, review\n[Reading and writing application logs](/appengine/docs/standard/python/logs#writing_application_logs)\nin the App Engine documentation.\n\nThe Python logging module provides predefined log levels. In increasing order\nof severity, the log levels are:\n\nLoggers exist in a dot-separated hierarchy. For example, the logger\n`endpoints.api_config` is a child of the logger `endpoints`. This hierarchy\ngives you precise control over which logs are emitted or suppressed. Typically,\nyou only change the two root loggers for Endpoints Frameworks:\n`endpoints` and `endpoints_management`.\n\n### Enable `DEBUG` logging for Endpoints Frameworks\n\nTo avoid overloading the log reader, Endpoints Frameworks sets its\nloggers to only record log entries with the `INFO` log level or higher. At any\ntime after Endpoints Frameworks has been imported into your module,\nyou can change the log level as follows: \n\n import logging\n logging.getLogger('endpoints').setLevel(logging.DEBUG)\n logging.getLogger('endpoints_management').setLevel(logging.DEBUG)\n\nThe `setLevel` method sets the minimum log level for the logger."]]