views:

153

answers:

2

I have a REST server and a client application running on a mobile device. The client has some data and would like to get updates to the data from the server. How do I do this in a RESTful way in a single transaction?

Suppose the client has the following items:

  widget id=1 timestamp=2010-03-05T08:00:00
    doodad id=1 widget=1 timestamp=2010-03-05T08:10
    doodad id=2 widget=1 timestamp=2010-03-05T08:20
  widget id=2 timestamp=2010-03-05T09:00:00
    doodad id=3 widget=2 timestamp=2010-03-05T08:10

and the server has

  widget id=1 timestamp=2010-03-05T08:00:00
    doodad id=1 widget=1 timestamp=2010-03-05T08:10
    doodad id=2 widget=1 timestamp=2010-03-05T09:00
    doodad id=4 widget=1 timestamp=2010-03-05T08:30
  widget id=2 timestamp=2010-03-05T10:00:00
    doodad id=3 widget=2 timestamp=2010-03-05T09:10
    doodad id=5 widget=2 timestamp=2010-03-05T08:30

The server should return something like

  doodad id=2 widget=1 timestamp=2010-03-05T09:00
  doodad id=4 widget=1 timestamp=2010-03-05T08:30
  widget id=2 timestamp=2010-03-05T10:00:00
  doodad id=3 widget=2 timestamp=2010-03-05T09:10
  doodad id=5 widget=2 timestamp=2010-03-05T08:30

containing only the changed rows.

The client would like to tell the server what it has, so that the server can send updates. I do not want to do multiple connections to the server because the mobile connection is unreliable and I do not want to risk getting partial data.

If I were going to do multiple connections, I could probably have the client generate GET requests for each item that it has with the id and timestamp and the server could reply with nothing (304 Not Modified) or the updated values as appropriate. E.g.: "GET /widgets/{id};timestamp=xxx".

What is the best way to do the same thing in a single transaction? Could I do something like "GET /changes" and the body have the type (widget or doodad), id and timestamp values for each row that the client has already? I think I know how to return the values (as a collection of changes), but how does the client ask for them?

Thanks, Ralph

A: 

lookup on how to use etags, this kind of thing is what they are for. for small amounts of data it will just be faster to send the entire payload state rather than making multiple calls to the server for each resource.

fuzzy lollipop
I saw the stuff on ETags in the book RESTful Java, by Bill Burke, but that is a way for the server to state that there are no changes, not for the client to ask. I need a RESTful way for the client to ask about multiple values that it already has, without requiring the that client ask in many transactions.
Ralph
It is for the client to ask, you just have to pass in the if-none-match header on a GET. To do this in a batch you will have to roll your own handler with a POST to that URL and some body with all the resource ids that you want to test
fuzzy lollipop