Part of our RESTful API will allow users to register an item with a serial number. Since the serial number is not globally unique, it cannot be used as a resource identifier, so we will use POST for the parent resource that will generate the identifier, for example.
POST /my/items <item serial-number="ABCDEF" />
In the case when the element is not yet registered, the HTTP semantics are defined correctly. We return the Location header and the registered item as the body of the object, for example.
HTTP 201 Created Location: /my/items/1234 <item id="1234" serial-number="ABCDEF" />
However, when an element is already registered, the API must be idempotent and return the previously registered element without creating a new one. My best guess is that it should then return a 200 OK status code and use the Content-Location header to indicate where the item came from, e.g.
HTTP 200 OK Content-Location: /my/items/1234 <item id="1234" serial-number="ABCDEF" />
It would seem reasonable? I donβt quite understand if Location or Content-Location is suitable in the second case.
Greg beech
source share