Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
280 views
in Technique[技术] by (71.8m points)

rest - Idempotent POST methods header in response

I'm implementing an idempotent POST method. So in the request, I have a mandatory header X-Request-Id.
On the backend, I'm checking if there is a recourse with the same X-Request-Id system is returning the existing one and not creating a new resource.

My question is. Is there any standard response header, which should be returned in case of an already created resource?

question from:https://stackoverflow.com/questions/66058939/idempotent-post-methods-header-in-response

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I don't think there are any standards around that.

If, from your design POV, this should denote a success (albeit a special one), I'd go with 201 (ie CREATED) for the first invocation and 200 (ie OK) for the subsequent ones.

If you see it as an error (I'd find it odd though) then I'd pick 200 (ie OK) for the first call and 409 (ie CONFLICT) for the subsequent ones.

No matter which one you choose, the most important thing, as you already know, is to be consistent and predictable about that in your API.

MDN on status codes: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...