I'm working with a RESTful API where a POST
operation is used to create a user. A required field, which could be an email or a unique user nickname, is unique across the system. The response to this POST
contains a unique id for the user, which is a deterministic hash calculated from this unique field. Therefore, the same unique field will always produce the same id, preserving their one-to-one relationship.
Given this structure, there's an inherent challenge regarding the use of the PUT
operation. Traditionally, PUT
can replace a resource or create a new one if it doesn't exist. However, in this context, the deterministic and immutable relationship between the id and the unique field seems to complicate the semantics of PUT.
My concerns are:
- Given the deterministic nature of the id from immutable properties, is it a good design choice to implement a PUT method for such resources?
- If the semantics of PUT are challenged by this design, are there any best practices or potential pitfalls that I should be aware of?
id
is calculated from (possibly immutable) fields by an internal algorithm, which the API user is not supposed to know of. I don't think he is also supposed to know which feilds are used. So I don't feel comfortable requesting the user to provide a field (set of fields) with "exactly the same value". Such reuiqrement would be unfulfillable in such cases when the caller has a permission toreplace
an existing user, but is not allowed to know the personal details due to privacy reasons.