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, yousum
all transactions using javascript and youcount
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.
1 Answer 1
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.
-
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 etcJimmy Hoffa– Jimmy Hoffa2012年12月27日 21:04:43 +00:00Commented Dec 27, 2012 at 21:04
Explore related questions
See similar questions with these tags.
/transaction/sumation
and return all possible sums, average, count in one packet. BTW Im after discussion about REST (position: REST is overused when should be used business methods and stronger webservices). This problem seem in this class (IMHO)