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

1

6

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)?

Aurelia answered 10/5, 2017 at 4:22 Comment(2)
PouchDB implements the CouchDB replication protocol which is based on REST. You might need to implement it aswell. See also the PouchDB docs on this...Commando
thanks for that info. The replication protocol doesn't look too complicated, but still quite a bit of work to implement probably. maybe a better idea might be to just have a pouchdb local storage in the client to which the webapp caches data from the REST webservice and stores data locally if no connection is available. As soon as the internet/server is back online, it sends it back to the rest webservice.Aurelia
T
2

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).

Tress answered 11/5, 2017 at 8:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.