vendredi 7 février 2020

RESTful API and stats page

I have a RESTful API that manages customers and payments.

I've been requested to create a stats page with data like:

  • total number of customers
  • how many customers are active/inactive
  • total number of payments
  • how many payments failed/were successful
  • how many payments failed/were successful per day
  • how many payments failed/were successful per month
  • how much money was earned per day
  • how much money was earned per month
  • and other more

I have endpoints for everything and I can retrieve customers calling api/customers and payments by calling api/payments. I know I could call api/payments?status=successful and api/payments?status=failed to get the data that I need, however the system has hundreds of payments and thousands of customers and each query takes its time to process. Also, I know I could retrieve all payment stats with a single query with a group by statement.

My question is: would it break RESTful conventions to create a new endpoint for each required stat? This would allow me to create "optimized" queries for each metric.

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire