Yoshevski
2 min readJun 28, 2020

--

Reducing API response size

We are all well familiar with the REST API(s) and using them on a daily basis for development of various applications.

Even so there are many different patterns of how the API response can be optimized by using various techniques, also server cache etc. in most of the cases we ignore the fact that we (developers) are the cause of big size of the data returned back, because of duplication.

In most of the cases we have following json (example) response:

where almost 50% of the size of the data returned is taken by the object keys.

There is simple solution to overpass this issue and spend at least 30–50% less traffic in data transfers. By making following update of the sample above:

where in the fields, we keep the keys (property names) for each object, and in data we have array of arrays or of object depends on your preference, which contains data in order to match the fields property (in same order).

This of course will require extra “for loop” or similar on front end side to match the fields with data in order to get the object format as on the first image, which is insignificant usage of cpu and ram in most of the cases, compared to reduced network transfer.

Thanks for reading.

--

--

Yoshevski

Long time in the IT field as fullstack developer.