Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using PouchDB as offline client-side temporary storage for a regular RESTful webservice

I have a server-side web application with a RESTful web API on top and a client side webapp that talks to it. I would like to implement offline storage and functionality in the webapp in case the server (or internet) is not available. Is it feasible to implement PouchDB on the client side, and have it sync with my restful webservice instead of a CouchDB database? What standards does the webservice need to adhere to to be compatible with couchdb/pouchdb? Does anyone have any examples about this or suggestions on how to do it differently if there is a better way (I'd prefer not to switch my backend from postgresql/python to couchdb if I can)?

like image 279
Dolf Andringa Avatar asked Oct 29 '22 07:10

Dolf Andringa


1 Answers

Is it feasible to implement PouchDB on the client side, and have it sync with my restful webservice instead of a CouchDB database?

Probably not. But it depends on your definition of "feasible".

What standards does the webservice need to adhere to to be compatible with couchdb/pouchdb?

It needs to implement the CouchDB Replication protocol.

Does anyone have any examples about this or suggestions on how to do it differently if there is a better way?

You have two options, which really boil down to the same thing:

  1. You can implement an existing replication protocol.
  2. You can write your own replication protocol.

The bottom line is: You need a replication protocol that both your client and server speak. This is not an easy task. Replication is hard.

PouchDB + CouchDB solves that hard part for you, but it comes at a price--it only replicates JSON data. Of course you can shoehorn other data into JSON docs, but then you're writing a new protocol again.

As you suggested in comments, you could use PouchDB just for local storage, and do your own replication. Sure, that's fine. Although if you're not using PouchDB's replication, it may not be the best local storage solution for you (but it is still a good one).

like image 190
Flimzy Avatar answered Nov 15 '22 10:11

Flimzy