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,[]]