POST/PATCH read only attibutes


#1

I have a resource which has some attributes that are read only (because they are calculated). I want these attributes to be available on GET but they will not change if there is a POST/PATCH.

What do I do for POST/PATCH? In the case where a client performs a GET, updates the object and sends it back as a PATCH, I don’t want to throw an error because they are sending back some read only attributes too. However, I do want them to know that the attribute will be ignored because it is read only. The client can then make the adjustments.

Does the specification allow for this?

I think perhaps the best solution is not to throw an error - because updating the resource is fine but to use the meta information to explain that some attributes are calculated and will be ignored. Is there a better way?


#2

I’m a bit confused by this. If you want them to adjust their behaviour, why wouldn’t you throw an error? If you’re happy to ignore the data and provide feedback via meta (this would probably be the approach I would take), why do you care whether or not the client adjusts their behaviour in future?


#3

Thanks for the feedback, I’m going to go with feedback in meta.

It’s not important to the API if the client adjusts their behaviour but it is helpful to the client developer to explain why parts of the resource do not behave like the rest. For example, if they POST to the service, setting a new value to the attribute and it doesn’t change then the API author will receive a bug.