If I misunderstood your question, I apologize in advance. With that said ...
But how can the client distinguish between records and read-only properties to present the user with the appropriate controls (for example, the HTML input field is disabled)
Well, there are several solutions. The simplest one I can think of is to make each property an object that has a simple structure of something like:
... someProperty: { value: 'some value', access: 'read-only' }, someOtherProperty: { value: 'some value', access: 'write' } ...
Obviously, you can do as creatively as you do with the way you represent the level of access to it (using enumerations, Booleans, changing access as isReadOnly or something else).
After that, the person using the API now knows that it is read-only or not. If they pass the βwriteβ value for the read-only property as part of the POST payload, then they should expect nothing but a 403 response.
Edit: If you cannot change the properties this way, there are a number of other ways that you can still achieve this:
- write documentation that explains how each property has access
- create a route along which the user can send 1 or more properties to receive a response that indicates the access level of each property (response: {propName: 'read-only', propName2: 'write', etc.)
- Returns an Access property map as part of the response (mapping properties for accessing levels).
end of the day, you just need a way to map the property to the access level. however, it depends on what your limitations and requirements are for the api, what changes you can make, and what is acceptable for both your client (s) and business requirements.
source share