Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google应用程序引擎:路由和分割应用程序后端的最佳实践(Python)_Python_Google App Engine_Google Cloud Endpoints - Fatal编程技术网

Google应用程序引擎:路由和分割应用程序后端的最佳实践(Python)

Google应用程序引擎:路由和分割应用程序后端的最佳实践(Python),python,google-app-engine,google-cloud-endpoints,Python,Google App Engine,Google Cloud Endpoints,我的问题很简单,尽管我花了几个小时浏览了官方的GAE python文档,但我还是没能找到这个问题的真正答案(尤其是在 假设我正在构建一个应用程序后端,该应用程序将发出几种类型的请求,所有请求都有一定的相关性,但它们都可以根据它们通过端点方法请求的数据类型进行分组。 现在,我构建了所有与这些请求相对应的messages.Message类,它们都位于单独的模块中。例如,我对所有与用户相关的请求/响应消息、所有与评论相关的消息和所有与调查相关的消息进行了分组(这是一个简单的调查应用程序) 问题是:在保

我的问题很简单,尽管我花了几个小时浏览了官方的GAE python文档,但我还是没能找到这个问题的真正答案(尤其是在

假设我正在构建一个应用程序后端,该应用程序将发出几种类型的请求,所有请求都有一定的相关性,但它们都可以根据它们通过端点方法请求的数据类型进行分组。 现在,我构建了所有与这些请求相对应的
messages.Message
类,它们都位于单独的模块中。例如,我对所有与用户相关的请求/响应消息、所有与评论相关的消息和所有与调查相关的消息进行了分组(这是一个简单的调查应用程序)

问题是:在保持简单的同时分割端点API的最佳(可能的)方法是什么(以避免在同一
remote.Service
类中有一个包含太多请求的大型文件)

我可以创建几个
remote.Service
类(然后将它们分发到多个模块中,然后将它们全部包含在一个模块中)吗? 像这样:

@endpoints.api(name='helloworld', version='v1')
class UsersApi(remote.Service):
    """Users API v1."""

   #some endpoints methods, all with the "users/ path"

class CommentsApi(remote.Service):
    """Comments API v1."""

   #some endpoints methods, all with the "comments/ path"

class SurveysApi(remote.Service):
    """Surveys API v1."""

   #some endpoints methods, all with the "surveys/ path"


APPLICATION = endpoints.api_server([UsersApi, CommentsApi, SurveysApi])
或者我应该使用app.yaml文件中给出的路由来路由请求吗? 这两种解决方案可能吗?他们是最好的吗

如果你能想出比我的建议更好的方法来实现这一点,那就告诉我更多。如果不清楚,我可以提供一些建议的代码示例。
提前感谢您的帮助。

不管怎样,我使用了这里和那里的一些信息,重新阅读了官方文件,测试了它,它成功了。 下面是一个例子:

from google.appengine.ext import endpoints
from protorpc import remote

my_api = endpoints.api(name='awsum_app', version='valpha')

@my_api.api_class(resource_name='users')
class UsersService(remote.Service):

    @endpoints.method(UserRegistrationRequest, UserLoginResponse, path='users/register', name='register')
    def user_register(self, request):
        """Registerin' users man"""

    @endpoints.method(UserLoginRequest, UserLoginResponse, path='users/login', name='login')
    def user_login(self, request):
        """Login dat user"""

    @endpoints.method(UserLogoutRequest, UserLogoutResponse, path='users/logout', name='logout')
    def user_logout(self, request):
        """Dude this user is so login out, cya bro"""

@my_api.api_class(resource_name='friends')
class FriendsService(remote.Service):

    @endpoints.method(AddressBookRequest, AddressBookResponse, path='friends/addressbook', name='addressbook')
    def get_address_book(self, request):
        """Retrieveing mah address book to look up bros to hand out with"""

    @endpoints.method(AddFriendRequestRequest, AddFriendRequestResponse, path='friends/friendrequest', name='friendrequest')
    def send_friend_request(self, request):
        """Hey dis bro looks cool let's add him"""

    @endpoints.method(AcceptFriendRequestRequest, AcceptFriendRequestResponse, path='friends/acceptrequest', name='acceptrequest')
    def accept_friend_request(self, request):
        """Ok man you're cool let's be friend"""

    @endpoints.method(DeleteFriendRequest, DeleteFriendResponse, path='friends/deletefriend', name='deletefriend')
    def delete_friend(self, request):
        """Shit dis fucker's a bitch i ain't no friend no more with this bitch"""

APPLICATION = endpoints.api_server([my_api])