5 ms·
Like all things, the answer is it depends. Returning consistent API responses will usually be better for future API consumers. If you are deciding between sendi
by dexwiz 5y ago
Like all things, the answer is it depends. Returning consistent API responses will usually be better for future API consumers. If you are deciding between sending back 1 field or 5 fields, it’s going to about the same since the overall request overhead will outweigh payload size. But if your widget has 500 fields, or deeply nested fields, it may be useful for the API to provide parameters that a consumer can use to specify which fields to return to avoid sending extra bytes.
The area I find dangerous for response sizes are load everything endpoints. Say it takes 5 API calls to build a page, you may have the great idea to create one Uber endpoint that returns the data for all 5 in a single call. These usually work initially but scale very poorly if your response body has any sort of list.
For delete it’s pretty common to not return much beyond the status code. If the object is successfully deleted, then it no longer has data, so what are you returning it for? If you need to store a snapshot before deletion, then send a GET first.
- julianlam 5y agoRight, and thanks for your thoughts. Doing a bit of code archaeology suggests that everything was kept minimal because the websocket implementation wasn't really meant to be used beyond the narrow scope of its initial implementation. Any updates (if we needed more data, for example), would just mean expanding the return payload with the necessary data. The whole question really comes into play specifically when looking at designing an API for public consumption, because you really then can't know what the end user wants to receive.