How to handle immutable and derived fields in an HTTP PUT? How to handle immutable and derived fields in an HTTP PUT? json json

How to handle immutable and derived fields in an HTTP PUT?


As I understand, you're developing the server side. Indeed, PUT, traditionally, used to update the existing record in your data layer. Therefore it's very useful to know the id of the record (not to have problem with querying the database with another attribute, like name, and get two similar records). Again, traditionally you should send all parameters to server to save it to database, or whatever you use in data layer. name_caps, on the other hand, is not an attribute in your data layer, but it's computed value. So the client does not need to send this parameter.

At the end of the day, if you and your team are in control of developing in both server and client side, and you don't plan to open your API to the world to be used by other developers, in fact, you can develop your server in a way that you see that it makes more sense. In this case, you can just expect all parameters but the id as optional for PUT calls. Of course thinking in the restrict restful terms, PATCH is the right method to use for sending partial data to server for update operation, but lots of APIs out there don't use it, mostly GET, POST, PUT are used methods and front end developers got used to them. Entry level front end developers might be surprised seeing that you require them to call PATCH.

Does it make sense?