9 ms·
You are one step ahead though. How can you address a resource if you don't know beforehand the representation of its identifier? Say, you want to create a new E
by kgtm 15y ago
You are one step ahead though. How can you address a resource if you don't know beforehand the representation of its identifier? Say, you want to create a new Employee under /Employees. Do you just issue a 'GET /Employees/1234' and assume '1234' is a valid identifier when you get a 404? What if the system expects a MongoDB _id such as '47cc67093475061e3d95369d'?
A workaround, as was suggested by an other poster, is that the client interrogates the system for a valid identifier and then proceeds. This especially makes sense when, as noted, you are dealing with resources that belong to no collection.
- ww520 15y agoAll these are good points. However, in the case where the Id is the nature key (e.g. SSN), the Id can be known from the user input. Creating an employee is just a matter of PUT his full record along with his SSN as the Id.
- itcmcgrath 15y agoSave yourself some hassle. Don't key on SSN. 1) Encryption (and then indexing) becomes harder. 2) SSN's can change, for many reasons. (eg: http://consumerist.com/2008/11/can-i-change-my-social-security-number.html http://consumerist.com/2008/11/can-i-change-my-social-securi..., data entry error, etc)
- ericHosick 15y agoIt is a bad idea to use anything entered by a user as the primary key. It is ok to use data entered by users to assure the uniqueness of a record (unique indexes/constraints).
- wahnfrieden 15y agoThe client shouldn't know how to assemble URLs. The better way to do this is to POST to /Employees and have the server return the URL of the newly-created employee.