How to enforce POST idempotency in DRF?

Viewed 1703

I have an API using Django Rest Framework that I'd like to protect against duplicate POST requests (in the spirit of Post Once Exactly (POE)). In particular, the scenario I'm trying to handle is:

  1. Client sends HTTP POST to create object.
  2. API backend creates the object and commits it to the database.
  3. Client loses network connectivity.
  4. API backend tries to send back a success response, but is unable to do so since the client lost network.
  5. The client never gets the "success" response, so assumes that the request fails. Client retries the request, creating a duplicate object.

There was some discussion about this on the mailing list but no code materialized. How are people solving this problem right now?

1 Answers
Related