Monday, 15 March 2010

http - Restful api data syncing only changed models on big collections -



http - Restful api data syncing only changed models on big collections -

i'm trying find best practice method create api respond 204. lets consider next simplified steps:

client get: server response 200 total collection of 10 records no changes made client get: server response 304 info not changed changes made record 5. record 11 added. record 2 deleted client get: server response 200 new collection of 10 records

for 10 records not big issue. when collection lets few thousands records don't want refresh entire locally stored collection. in case it's easier alter 3 updated models (delete record 2, update record 5, add together record 11) want this

client get: server response 200 total collection (paginated or not) no changes made client get: server response 304 info not changed changes made record 5. record 11 added. record 2 deleted client get: server response 204 info 3 changed records

in above case request cycle optimized, problem is: how server respond this. must send info client in either header or body. thinking exploiting last-modified-since header. date alter on server. client stores date when status 200 or 204. when client sends header server, server respond records changed or deleted since then. example:

{ "total": 113440, "from": 0, "till": 2, "count": 3, "removed": [1,2], "parameters": [{"id"}, {"title"}], "collection": [ { "id": 3, "title": "updated record" }, { "id": 4, "title": "new record" }, { "id": 5, "title": "another new record" } ], }

downside server more complex because needs maintain track of deleted info , lastly updated records.

keep in mind did think of sending silent force updates don't want since user not happy background info traffic.

what guys think solutions , have similar or improve solution keeping next in mind?

lower amount of needed requests make api descriptive , cellular (api beingness it's own documentation allowing clientside generators) be live possible effectively deal huge collections (ex: pagination, fetch updated records, caching etc)

you send if-modified-since header requests collection. endpoint homecoming contents have changed since provided date.

note not behaviour specified the http spec conditional requests. consider whether approach want take. not suggest it.

in spec written, there no way i'm aware of retrieve subset of collection conditionally. closest can think of have collection contain links individual elements. create client phone call on each individual element, using if-none-match or if-modified-since pass stale entities on wire. you'd still have create server nail collection entity, though utilize conditional header on request.

http rest caching collections metadata

No comments:

Post a Comment