Sunday, October 20, 2013

Mobile App + Cloud Backend

I wanted to set up a cloud back end for my Android application for a few reasons:
  • To practice and learn about cloud and web development.
  • To improve my Android app by backing up user data and to provide additional analysis based on a more full history for a given user and aggregated data from multiple users.
As a beginner web programmer, I didn't know where to begin.  Despite some criticisms, I turned to Google Cloud Endpoints in Python to provide a solution.  This works with Google App Engine and gives you a bunch of things: such as user authentication, data storage, ways to generate libraries for different clients (such as Android or the web) and scalability (although my user base is pretty small for now).

I started with this sample tictactoe application.  After a few minutes I got the sample application to work on my local machine.  When I moved the application to the cloud as a Google App Engine application, I got errors about "Origin mismatch".  The resolution was to make sure you registered any clients with the correct url.  This includes matching the protocol type as well - ie use "https".

After a few hours (spread out over a few weeks) I was able to create some new request/response objects which are used in the messages passed to and from the back end to a client.  I think I have a decent feel for how things work. In my head, the cloud back end goes through the following steps.
  1. A Web Client (or Android) creates JSON (or java) message object. 
  2. Your generated backend libraries convert these message objects into some request object.
  3. The request object is then sent to one of your backend apis/methods.
  4. (In my case) I take the request object and put it into the Google App Engine datastore.  In your case, you can do whatever you want.
  5. A response message is created and sent back to the original web or mobile client.
  6. Your generated backend libraries convert the response message back into a message. 
  7. Your client can then do whatever they want with the response.
I haven't actually implemented or tested anything in the Android client, so we'll see if my thinking about how this all changes. 

No comments:

Post a Comment