Updating PUT endpoint receiving non-existing id [duplicate]
Imagine an updating PUT endpoint receives a DTO that contains an id that corresponds to no record. { id: 12345, name: "George" } Options I see: Do nothing. Return an error response. Create a new user with that id. Keep in mind it could theoretically be a typo. There may be a George in the datastore, albeit with a different id (say, 1234, not 12345). It may go against the client's expectations if the backend persists (or tries to persist) a brand-new George with a different id. What is the REST best practice? This question is unfocused, it's unclear what it asks. My question is focused and on-topic.
Imagine an updating PUT endpoint receives a DTO that contains an id that corresponds to no record.
{
id: 12345,
name: "George"
}
Options I see:
- Do nothing.
- Return an error response.
- Create a new user with that id.
Keep in mind it could theoretically be a typo. There may be a George in the datastore, albeit with a different id (say, 1234
, not 12345
). It may go against the client's expectations if the backend persists (or tries to persist) a brand-new George with a different id.
What is the REST best practice?
This question is unfocused, it's unclear what it asks. My question is focused and on-topic.