API의 각 클래스에 대해 동일한 이름을 사용하는 한, api_collection를 원하는 이름으로 바꿉니다. 위 스니펫에 표시된 것처럼 API의 각 클래스 앞에 데코레이터를 두어야 합니다.
resource_name 인수 정보
api_class의 선택사항인 resource_name 인수는 API에 노출하려는 클래스의 이름입니다. API 탐색기에도 이 이름이 표시되며, 클래스에 노출된 모든 메서드 앞에 추가됩니다.
path 인수 정보
api_class의 선택사항인 path 인수는 URL에서 클래스 메서드가 표시되는 상대 위치를 지정합니다. 앞의 예시에서 Shelves 클래스에 path가 지정되지 않았으므로 루트 /_ah/api/library/v1 아래에서 해당 메서드에 액세스할 수 있습니다. 예를 들어 /_ah/api/library/v1/list 경로에서 list 메서드에 액세스할 수 있습니다.
클래스에 path 인수를 지정하면 지정된 경로가 루트에 추가됩니다. 앞의 예시에서 Books 클래스에 path 인수 books가 지정되었으므로 /_ah/api/library/v1/books 아래에서 해당 메서드에 액세스할 수 있습니다. 예를 들어 /_ah/api/library/v1/books/best_sellers_list 경로에서 best_sellers_list 메서드에 액세스할 수 있습니다.
메서드의 경우 path 인수는 선택사항입니다. path를 지정하지 않으면 메서드 이름이 사용됩니다. 메서드에 지정된 경로는 클래스 경로에 추가됩니다. 위 예시에서는 bookmark가 get_bookmark 메서드의 path로 지정되었습니다. /_ah/api/library/v1/books/bookmark 경로에서 get_bookmark 메서드에 액세스할 수 있습니다.
/로 시작되는 메서드 path 인수를 지정하면 클래스 path 인수를 재정의할 수 있습니다. 예를 들어 Books 클래스의 get_bookmark 메서드 경로가 다음과 같다고 가정해 보겠습니다.
[[["이해하기 쉬움","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-03-25(UTC)"],[[["\u003cp\u003eThis guide demonstrates how to structure an API across multiple classes using decorators, contrasting with single-class API setups detailed elsewhere.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003e@api_collection.api_class\u003c/code\u003e decorator is used to designate classes that contribute to the API, with \u003ccode\u003eresource_name\u003c/code\u003e setting the class's API Explorer name.\u003c/p\u003e\n"],["\u003cp\u003eThe optional \u003ccode\u003epath\u003c/code\u003e argument in \u003ccode\u003e@api_class\u003c/code\u003e and \u003ccode\u003e@endpoints.method\u003c/code\u003e determines the URL structure for classes and methods, appending to the root API path, or overriding the class path with a leading \u003ccode\u003e/\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eMethods within classes are made accessible via the API using the \u003ccode\u003e@endpoints.method\u003c/code\u003e decorator, and without a specified path the method name is used.\u003c/p\u003e\n"],["\u003cp\u003eYou must use the \u003ccode\u003eendpoints.api_server\u003c/code\u003e code and pass in your \u003ccode\u003eapi_collection\u003c/code\u003e variable to the function to serve the multi-class API.\u003c/p\u003e\n"]]],[],null,["# Creating an API implemented with multiple classes\n\nThis page describes how to decorate your code to create an API implemented in\nmultiple classes. If you implemented your API using only one class, see\n[Creating the API](/endpoints/docs/frameworks/python/create_api).\nSee\n[Decorators](/endpoints/docs/frameworks/python/decorators-reference)\nfor detailed information about all the available decorators. \n\n api_collection = endpoints.api(name=\"library\", version=\"v1.0\")\n\n\n @api_collection.api_class(resource_name=\"shelves\")\n class Shelves(remote.Service):\n @endpoints.method(Request, Response)\n def list(self, request):\n return Response()\n\n\n @api_collection.api_class(resource_name=\"books\", path=\"books\")\n class Books(remote.Service):\n @endpoints.method(Request, Response, path=\"bookmark\")\n def get_bookmark(self, request):\n return Response()\n\n @endpoints.method(Request, Response)\n def best_sellers_list(self, request):\n return Response()\n\nReplace `api_collection` with any name you want, so long as you use\nthe same name for each class in the API. You must precede each class in the API\nwith the decorator as shown in the preceding snippet.\n\n### About the `resource_name` argument\n\nThe optional `resource_name` argument for `api_class` is the name of the class\nthat you want to expose in the API; this is the name that shows up in the\nAPI Explorer, prepended to any methods exposed in the class.\n\n### About the `path` argument\n\nThe optional `path` argument for `api_class` specifies the relative location at\nwhich the class methods appear in the URL. In the preceding example, a `path`\nisn't specified for the class `Shelves`, so its methods are accessible under the\nroot, `/_ah/api/library/v1`. For example, the `list` method is accessible from\nthe path `/_ah/api/library/v1/list`.\n\nIf you specify a `path` argument for a class, the specified path is appended to\nthe root. In the preceding example, the `path` argument `books` is specified for\nthe class `Books`, so its methods are accessible under\n`/_ah/api/library/v1/books`. For example, the `best_sellers_list` method is\naccessible from the path `/_ah/api/library/v1/books/best_sellers_list`.\n\nThe `path` argument is optional for methods. If you don't specify a `path`, the\nmethod name is used. Any paths specified for methods are appended to the class\npath. In the preceding example, `bookmark` is specified as the `path` for the\n`get_bookmark` method. The `get_bookmark` method is accessible from the path\n`/_ah/api/library/v1/books/bookmark`.\n\nYou can override the class `path` argument by specifying a method `path`\nargument that begins with `/`. For example, assume that the `get_bookmark`\nmethod in the `Books` class has the following path: \n\n```\n@endpoints.method(Request, Response, path='/bookmark')\ndef get_bookmark(self, request):\n return Response()\n```\n\nThe leading slash changes the path for the `get_bookmark` method to\n`/_ah/api/library/v1/bookmark`.\n\n### Serving a multi-class API\n\nIn your [endpoints.api_server](/endpoints/docs/frameworks/python/api_server)\ncode that creates the API server, you supply the name you assigned for your\n`api_class` collection. For example, where the collection name is\n`api_collection` you would create the server as follows: \n\n api = endpoints.api_server([api_collection])\n\nWhat's next\n-----------\n\n- [Creating the API](/endpoints/docs/frameworks/python/create_api)\n- [Decorators](/endpoints/docs/frameworks/python/decorators-reference)"]]