Ivan-Johnson / LifeLogServer

A DIY life tracking app
0 stars 0 forks source link

Cache responses #5

Closed Ivan-Johnson closed 4 years ago

Ivan-Johnson commented 4 years ago

At present, the API is rather naive. If a client sends a POST request to add a new entry but does not receive a response from the server, they obviously have no way of knowing if the POST succeeded or not. Their best option at present is to send a GET to check and see if the new entry was recorded or not, and then send another POST if necessary.

A better option is for the POST endpoint to take a RequestID parameter. When a particular RequestID is processed for the first time, a copy of the response can be saved in a cache. Then if the client does not receive the response, they can simply make the exact same request again and the server will return the original response without processing the same request multiple times.

Ivan-Johnson commented 4 years ago

It should be feasible to implement this as a python decorator.

Ivan-Johnson commented 4 years ago

Although arguably secure with the current policy where there is only one user and all tokens have the same privileges, it would be better to have a future proof solution that requires the original request and the followup request be using the same token.