RESTful API design: should unchangable data in an update (PUT) be optional?

Personally, both ways are acceptable…. however, if I were you, I’ll opt for option A (check read-only fields to ensure they are not changed, else throw an error). Depending on the scope of your project, you cannot assume what the consumers know about your Restful WS in depth because most of them don’t read documentations or WADL, even if they are the experienced ones. 🙂

If you don’t provide immediate feedback to the consumers that certain fields are read-only, they will have a false assumption that your web service will take care all the changes they have made without double checking, OR once they find out the “inconsistent” updates, they complain to others that your web service is buggy.

You can approach this in two different ways if the read-only field doesn’t match the original values…

  1. Don’t process the request. Send a 409 Conflict code and specific error message.
  2. Process the request, send a 200 OK and a message stating that changes made the read-only fields are ignored.

Leave a Comment

tech