04-Servers in the mobile architecture - Continued

Homework required in preparation for this lecture

  1. Preparation to build your apps server
    1. Come up with a revision of the tables and columns you want in each table
    2. Designate one team member to be the server person
      1. Must be a mac user
      2. Must be willing to put in some extra work :)
      3. At least one, but more than one may attend :)
    3. Deliverable: Revise your blog post from yesterday if necessary, include your server person's name
  2. Read about connecting to web services
    1. Here are some links to skim over. Note: I have not tried these. They look promising, but no guarantees!
      1. Connecting to Web Services
      2. Calling a Web Service from Java
      3. Putting Java to REST
      4. Calling a REST WEb Service from Android
      5. Resty - A Java library for REST
    2. Note: I sent out a Homework Alert, deferring the rest of this homework. It is not due tomorrow.
    3. Write a test program that pulls information from one of the services mentioned yesterday
      1. Try using the RESTY library jar, which is written up here: Resty
    4. Or, write a test program that pulls information from the Voguable service
      1. http://vogueable.heroku.com/users.xml
      2. http://vogueable.heroku.com/users/1.xml
      3. http://vogueable.heroku.com/items.xml
      4. http://vogueable.heroku.com/items/1.xml
      5. This should be non GUI Java application which prompts the user for a parameter, and displays the result that came from the server. For example, if applied to the vogueabe.heroky.com service, it might look like this:
*** Vogueable Service Demo Utility ***
Do you want to see users or items (u or i): u
I found 3 users. Which user do you want to see: 2
User 2 is "Pito Salas", his email is pitosalas@gmail.com
Submit your code to Github, and create a screencast showing a demo of it

Creating a simple server

Our goal

  • We need a simple server to be the back-end of our mobile application
  • There are many many ways of doing this.
  • The baseline will be a Rails 3.0 database-only application
  • We will do the minimum amount of work


  • Representational State Transfer. See Wikipedia article on REST
  • Treat all the data on the server as a tree, accessible by formulating URIs
  • http://www.salas.com/2003/05/31/no-i-dont-really-have/
    • see it as a nested 'address' of a 'resource'
  • GET - the resource from that address
  • PUT - store the resource at that address
  • POST - store something new at a new address
  • DELETE - delete the resource at the specified address

Connecting the worlds

  • How then do we really connect the android app to the service?
  • Use a server proxy class to 'stand in' for the service on the android side
  • Look at the diagram

Ruby and Rails

  • What is Ruby? Quick demo
    • irb
    • no variable declararations
    • eval
    • blocks
    • re-opening a class
  • What is Rails? Relationship
  • Alternatives

Demo 1

  • Create a hello world Rails app
  • Add a generated model
  • Demonstrate how it works
  • Review the code

Flow Explanation

  • With a diagram explain exactly how the request travels:
    • client
      • send url to server
    • server
      • url is parsed
      • correct controller is chosen
      • controller uses the model to determine what to return
      • controller invokes the view to generate the html
      • controller returns html to client
    • client
      • receives html
      • displays it for user

Demo 2

  • Gaspar will demonstrate the server for Voguable app and explain its tables

Demo 3

  • Build one more demo

Afternoon Schedule

  • Pito meets with the designated server people for each team and helps them build the first server
  • Work with clients