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)?
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:
- You can implement an existing replication protocol.
- 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).
© 2022 - 2024 — McMap. All rights reserved.