Suppose i have entered the fields in my requestDto and made a post call which will save the data in database and if i again hit the post api with same requestDto fields, the entries should not be saved. How i can achieve this functionality in spring boot
Asked
Active
Viewed 938 times
2
-
1REST calls should be independent from each other, keeping track of each other in such a manner is anti-pattern for RESTful, but you can store some id, or maybe hash of the payload maybe, if those match you can reject or ignore the request? – buræquete Nov 03 '18 at 17:24
1 Answers
1
Bear in mind that POST
requests are not idempotent: with multiple identical requests you may end up with multiple identical resources getting created.
So, to prevent resources from getting created multiple times, you'll need some sort of validation in your server. You could rely, for example, in a unique constraint in your database and, if the constraint is violated, you can refuse the request with 409
.

marc_s
- 732,580
- 175
- 1,330
- 1,459

cassiomolin
- 124,154
- 35
- 280
- 359