Well, as I understand it, you’re talking about omitting a null attribute. For example, instead of returning:
{
atributo1: "Hello",
atributo2: null,
}
Your colleague recommends:
{
atributo1: "Hello"
}
This is not recommended and I believe that data saving is insignificant in most cases.
Your API contract must return (sponse) always the same fields, as omitting one of them leads to breach of contract and can cause various problems understanding your API. Already in sending (request) you can be more flexible yes, but aiming for API flexibility (to evade a version of the API, for example) and not data saving.
Finally, according to the principle of robustness (or Postel’s Law) alert us:
Postel’s Law States that you should be liberal in what you
Accept and Conservative in what you send.
What do you mean
par
? Can you give an example? Well, as I understand it, this is not recommended and I believe that data saving is insignificant in most cases. Your API contract should always return (Answer) the same fields, as omitting one of them leads to breach of contract and can cause various problems understanding your API. On the request you can be more flexible yes, but aiming at API flexibility and not data saving.– Dherik
As good REST practices you should always use the requisition protocols. In this case that there is no data you must return the status code 204 which means Nocontent(without content). This way you respect the request protocols and save data traffic on the network.
– Maycon F. Castro
@Dherik when I say "pair" I mean the attribute and its value. Example: {"code":245}. But I understood what I meant. Thank you.
– Tiago Aguiar
If you are concerned about this, you should not even use JSON, but a binary protocol, and omit everything that is not information at all. The rest is bullshit. Either use a standard exactly as defined, or do yours intelligently, to meet your requirements.
– Bacco