[[["わかりやすい","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\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)"]]