3

I'm beginning work on a project which has, as one component, the need to synchronize files from a server to a local HTML5 IndexedDB store for offline usage, then later, the option to push changes from the IndexedDB store back to the server.

But before I re-invent the wheel on something that should be a pretty straight-forward process, I'm hoping to find a well documented standard API (if not client and/or server libraries) to do most of the heavy lifting.

I would also like my project to maintain a bit of openness, so adhering to an open standard (even if I have to write both the client and server side code in my particular case) is a big win.

WebDAV is a clear candidate for this task, but tracks a lot of meta data (authorship info, etc) that isn't particularly relevant to me, and it adds a lot of HTTP verbs, which I would rather not deal with (to be more consistent with a modern understanding of RESTful), and it is just generally a heavier protocol than I need for my limited task.

Are there any alternative free standards for such an API?

1

CouchDB, and the closely related JavaScript client PouchDB have proven to be very nearly exactly what I was envisioning.

It doesn't use a purely REST-compliant API, but the details are cleanly enough hidden beneath the complete, and well-documented API, that in my case it doesn't matter.

PouchDB has a very active user and development community, and CouchDB is starting to get back into the swing of things, after a bit of a hiatus, apparently, with an upcoming release of 2.0.

-1

HTTP already has these features and is the point of REST.

Quoted from spec http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

GET

The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.

PUT

The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI. If a new resource is created, the origin server MUST inform the user agent via the 201 (Created) response. If an existing resource is modified, either the 200 (OK) or 204 (No Content) response codes SHOULD be sent to indicate successful completion of the request. If the resource could not be created or modified with the Request-URI, an appropriate error response SHOULD be given that reflects the nature of the problem. The recipient of the entity MUST NOT ignore any Content-* (e.g. Content-Range) headers that it does not understand or implement and MUST return a 501 (Not Implemented) response in such cases.

DELETE

The DELETE method requests that the origin server delete the resource identified by the Request-URI. This method MAY be overridden by human intervention (or other means) on the origin server. The client cannot be guaranteed that the operation has been carried out, even if the status code returned from the origin server indicates that the action has been completed successfully. However, the server SHOULD NOT indicate success unless, at the time the response is given, it intends to delete the resource or move it to an inaccessible location.

The point of REST is you implement them as needed to store/save/delete the content as needed from your back end store.

Storing inside IndexDB is fine but you will need some form of status I am not aware of a library which does this as it is basically very simple. You may want to hold a transaction log table which you use to propogate back information.

(I believe phonegap doesn't support IndexDB it uses WebSQL but there is a poly fill to use IndexDB API into WebSQL available)

  • 4 verbs does not a file-sync API make. – Flimzy Apr 24 '15 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.