Save JSON file information to database

1

I think about the possibility of a Web system saving information from a register in a JSON file on the client device, and that would later be sent to the DB. This will happen when the client is in an environment where it is not possible to access the internet at the moment of the registration to synchronize with the online BD. Is there any divergence or best practice for this implementation?

    
asked by anonymous 24.06.2018 / 23:51

1 answer

3

This is not complicated, especially being Web-based.

All client environment environments have a Storage area - even browsers . Usually these storage areas work simply with key and value - key value .

You can implement something like the following pseudo code:

sendData = (data) => {
  _http.send(data, 
    (response) => { success(response); },
    (error) => { _retryStorage.add(data); });
};

So, having a service periodically doing something like:

var data = _retryStorage.pop();
data && sendData(data);

So, if you have not been able to send the data to the server, then throw it into storage to get it back. Then another asynchronous service will "listen" to this queue, and if you have something there, try to re-send.

Remember that this is just a pseudo code, there is a lot to develop to work as expected, but it's a good way to go.

    
25.06.2018 / 10:35