We work with a Java platform on the server side with an html front end and Rest service calls to handle the communication. The client requests a form from the server with one Rest request. They fill out the form and submit it with a separate Rest request.
When a user submits the form: If the client does not get a response from the server within a few seconds we send another request, and then another until we finally get a response back. The problem is that if the first request processed, but we didn't get the response back, then subsequent requests will also process and give us duplicate entries.
What we need is a way to do something like this: The client requests a form. Lets process that request on the server as usual, but then generate a unique ID and store it on the server. Then we can send that ID back to the client along with the form response. Once the client receives this identifier, it will add it to the request object for the submission of the form. The server receives the the request and says "this is a legit ID. lets process the request, and then discard the ID on our end." Then if another request comes through with the same ID, the server says "I don't have this ID anymore. I cannot process this request".
I can see this being done by generating an ID on the fetch request, storing it to a file, retrieving the ID on form submission and then discarding the ID from the file. This feels like a clumsy way of doing it though. Is there an API or design pattern that would handle this more gracefully?
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire