Say my application has users, and each user is uniquely identified by their email address. In that case, it makes sense to use the natural key of email rather than using an auto incrementing ID as the primary key, which is common in most systems.
Then, in my REST API, would it be okay to access a particular user like this?
https://api.whatever.com/v1/users/[email protected]
Traditionally, you'd use the user ID in place of [email protected]
, but in my application the email address is the unique identifier for user accounts.
What would you pick? Using email as a natural key in REST URLs or create a user ID field to use instead?
I would use a user id. A person and their email address don't have a 1 to 1 relationship and they don't have the same life cycle, so using one as the identifier for the other is a bad idea.
People may have more than one email. Maybe they don't have an email account (it happens). Maybe they change their email. If you use the email address as the key, you might run into problems later on.