0

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

2

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

2
  • Hmm it would make the api more brittle though but I guess that's normal anyways.
    – paul23
    Commented 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
    Commented Sep 23, 2021 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.