質問

Not sure if this has an actual answer or not, but here goes.

I'm building a webapp, using webapp2 on appengine that will only expose a JSON API to the clients (other than shell HTML templates for browser-based clients).

What I have now is a main.py that routes incoming URLs to handlers. The handlers are separated into modules by function (ie user_auth, user_info, groups, etc...). I have a models.py module where my ndb.Models live.

The lowest level code involving the Models are contained in the Model subclasses in models.py (ie the models.Group has a classmethod called create_group, which is called by groups.AddGroupHandler.add_group, which is called by groups.AddGroupHandler.post.)

I also have an api.py module that contains classes for all of the webapp's behavior (ie api.UserAuth, api.Signup, api.RegistrationVerification, etc...) which contains classmethods that return JSON for those behaviors (ie api.UserAuth.session_expired, api.RegistrationVerification.bad_token, etc...).

The methods in api.py are called from the "low-level" methods in models, the "helper" methods in the handler modules (ie groups.AddGroupHandler.add_group, etc...), and the handler methods themselves (ie groups.AddGroupHandler.post, etc...).

Is this structure going to cause issues in the future, or is it fine as is? Also, are there any standard structures that are known to work for this kind of project?

EDIT: I'm not using REST or anything like that.

役に立ちましたか?

解決

I'd highly recommend you look into Google Cloud Endpoints as it allows you to build out an API using the endpoints framework and then Google provides client libraries for you to leverage so you don't have to roll your own iOS, Android, Javascript, etc front end code to communicate with your service layer.

https://developers.google.com/appengine/docs/java/endpoints/

There's a bit of a learning curve but once you get through it, it's a nice feature to work with. It also includes things like OAuth 2.0 support built in which otherwise you'd need to roll your own if you want to have authentication on your service layer.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top