Friday, 15 January 2010

Google App Engine: Best practice for routing and segmenting an app backend (Python) -



Google App Engine: Best practice for routing and segmenting an app backend (Python) -

my question pretty simple, , though scoured official gae python doc hours, wasn't able find real reply question (especially on this page)

let's i'm building app backend, , app create several kinds of requests, related, can grouped kind of info request through endpoints methods. , built messages.message classes corresponding theses requests, located in separate module. instance, grouped user-related requests/response messages, comment-related messages, , survey-related messages (it's simple survey app).

the thing is: best (possible) way segment endpoint api while keeping simple (in order avoid having 1 huge file many requests in same remote.service class).

can create several remote.service classes (and distribute them on several modules , include them in single module)? this:

@endpoints.api(name='helloworld', version='v1') class usersapi(remote.service): """users api v1.""" #some endpoints methods, "users/ path" class commentsapi(remote.service): """comments api v1.""" #some endpoints methods, "comments/ path" class surveysapi(remote.service): """surveys api v1.""" #some endpoints methods, "surveys/ path" application = endpoints.api_server([usersapi, commentsapi, surveysapi])

or should utilize routing given in app.yaml file route requests? 2 solutions possible? best?

if can come improve way accomplish propositions, go ahead tell me more it. can provide code illustration of suggestions if unclear. in advance help.

well anyway, used info here , there on stackoverflow, , re-read official doc, tested it, , worked. here's example:

from google.appengine.ext import endpoints 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 user 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 bros 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 together him""" @endpoints.method(acceptfriendrequestrequest, acceptfriendrequestresponse, path='friends/acceptrequest', name='acceptrequest') def accept_friend_request(self, request): """ok man you're cool let's friend""" @endpoints.method(deletefriendrequest, deletefriendresponse, path='friends/deletefriend', name='deletefriend') def delete_friend(self, request): """shit dis fucker's bitch ain't no friend no more bitch""" application = endpoints.api_server([my_api])

python google-app-engine google-cloud-endpoints

No comments:

Post a Comment