Possible Duplicate:
REST response code for invalid data
Have the following REST resource:
POST /user/{primary_key}
The resource is intended to work like an “ADD/UPDATE” operation. This means that it can be used to:
- Create a new user
- Update information on an existing user
If a client wanted to create a new user, some information is required:
POST user/{pimary_key}
Paylod:
- Username - (must be unique)
- Password
If a client wants to simply update an existing user, the call only needs to include the primary key and the new/changed information. For example:
POST user/{pimary_key}
Paylod:
- favorite hamburger type
This situation creates the potential for several requests from the client that are invalid:
- CONFLICT – The client updates an existing user attempting to change the
usernameto a value that is already in use by a different user. - MISSING INFORMATION – The client attempts to create a new user without including necessary information such as the username and password.
What are the correct HTTP response codes to return in these cases?
Thanks so much!
I would only recommend to separate creation and editing, and use different methods for them – POST to create, PUT to update. What if the user was going to modify something, but had a typo? It is better to show an error