Middle
What happens if an attribute is not passed or null/0 is passed in PUT and PATCH requests?
sobes.tech AI
Answer from AI
If an attribute is not provided in a PUT request, it usually means that the attribute should be updated or replaced with a default value or removed, as PUT implies a complete replacement of the resource.
If null or 0 is provided, the behavior depends on the API implementation:
- null may be interpreted as an explicit removal or nullification of the field.
- 0 as a specific value that will be written to the field.
In PATCH requests, which are intended for partial updates, the absence of an attribute means that this field is not changed.
Passing null in PATCH may mean removing or nullifying the field if supported by the server.
Thus:
- PUT without an attribute — the field can be reset or removed.
- PATCH without an attribute — the field remains unchanged.
- null/0 — specific values that the server may handle differently depending on the logic.