Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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:

  1. 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.

  2. 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.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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.

share|improve this answer
2  
+1 for the general statistics endpoint of "aggregate" or sometimes a "stats" etc. There are always some small set of commonly relevant aggregates which can be put together for ease of reporting, like average transaction amount, average transaction time, largest transaction, smallest transaction etc etc –  Jimmy Hoffa Dec 27 '12 at 21:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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