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?