Well in a page in our spa application we need to request some dynamic data from the server. Besides this data for display purposes we also need to request explanations of the columns from the data (each set of data might have different columns which are not static).
Normally in any application those are two distinct things to do and hence have different functions. Even thought they typically are requested in tandem.
However I wonder in a website wouldn't this be needlessly wasting bandwidth and speed, as suddenly the page is displayed based on the slower of the two responses? So wouldn't it be better to combine the data in a single request?
1 Answer 1
I don't think there is a compelling reason why combining the data transfer in a single request needs to violate the SRP:
the server or backend will provide an API which returns a complex object, which may consist of data and meta data like descriptions
creating and filling that object might be split up to into different tasks, with different functions on the server side, each one responsible for getting one part of the object. There will probably one function responsible for coordinating the individual function calls
the client will the get the whole object in one request and can evaluate the parts, maybe using individual functions as well
-
Hmm it would make the api more brittle though but I guess that's normal anyways.paul23– paul2309/23/2021 10:10:41Commented Sep 23, 2021 at 10:10
-
@paul23: this depends on how the passed object look like, and how you take care for backwards compatibility. In fact, since we are talking about web APIs, I guess the object is nothing but a JSON string, and that's a good basis for very stable API, even with complex data. When you extend the object, make sure the backend keeps providing valid values for each attribute which was mandatory in the past. Moreover, the client should make sure they check what they got from the backend, and can handle optional attributes.Doc Brown– Doc Brown09/23/2021 11:45:35Commented Sep 23, 2021 at 11:45
Explore related questions
See similar questions with these tags.