REST best practice: client-server synchronization

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

Suppose a customer has the following elements:

  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

contains only modified rows.

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

, , GET , , (304 Not Modified) , : "GET/widgets/{id}; timestamp = xxx".

? - "GET/changes", ( doodad), id timestamp , ? , , ( ), ?

,

+3
2
0

, etags, . , .

0

Source: https://habr.com/ru/post/1735604/


All Articles