For example, if I have a Customer Transactions Table and I create a REST for it.
ID: 646625 • Letter: F
Question
For example, if I have a Customer Transactions Table and I create a REST for it. The fields are: date, description, and total_amount.
I am trying to figure out which one is much more efficient when you get the sum and the count of the transactions:
You create a REST for /transactons URI and it lists down all the transactions. Then, you sum all transactions using javascript and you count all transactions using javascript.
You create a REST for /transactions/count and /transactions/sum URI and lists down count and sum for all transactions. Then, get the count and sum using javascript.
I'm wondering which one is a better way.
Explanation / Answer
It depends on how many transactions you expect. In general, it seems that if you only want the sum and count then transferring all the details is inefficient.
However, if the number of transactions is very small then the overhead of multiple requests might be more inefficient.
Personally, I like the second option, but I would add a third REST endpoint /transactions/aggregate that returns some or all of the aggregate data.a
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.