Dariusz Mydlarz
Dariusz Mydlarz

Reputation: 3002

REST: URI and method to get resource statistics

What is the correct (best) way to get statistics of a resource. E.g. I have such a resource

/tournaments

Which returns a list of tournaments (let's say paginated):

{
    items: [
        {
            id: 1,
            name: ...,
            created: ...,
            ...
        },
        {
            id: 2,
            name: ...,
            created: ...,
            ...
        },
    ]
}

I want to show a year chart with columns showing how many tournaments were created in a month. So I need something like these:

[
    year: 2014,
    month: 1,
    tournaments: 10,
],
[
    year: 2014,
    month: 2,
    tournaments: 8,
],
[
    year: 2014,
    month: 3,
    tournaments: 42,
],
...

Where should be such content put? In /tournamets resource or somewhere else? Under GET request? Maybe something like these:

/tournaments/stats?year=2014

How should it look like? Or maybe I should add those statistics to every /tournament response, beside to items node?

Upvotes: 2

Views: 277

Answers (1)

user1907906
user1907906

Reputation:

How do you GET a single tournament? If you use

GET /tournaments/1234

where 1234 is the ID of one tournament, I think is not a good idea to use

GET /tournaments/stats

to get the statistics. /tournaments is a collection resource and stats is not the ID of one tornament in this collection.

So I'd use a different resource, for example

GET /tournamentsstats

which could then be filtered

/tournamentsstats?year=2014

Upvotes: 1

Related Questions