Emilio
Emilio

Reputation: 1044

REST good practices: new resource or parameter?

I'm designing a RESTful API and I have a pretty simple "philosophical" question:

I have a resource representing a set of values stored in a period of time:

loggers/2/data?begin=10h&end=12h

Doing this request I get the data stored by a Data Logger (with id=2) from 10:00h to 12:00h.

response:

[
{
    "data": "10h",
    "value": 10
},
{
    "data": "11h",
    "value": 15
},
{
    "data": "12h",
    "value": 9
}
]

Now, I want only the max value in this period:

[
{
    "data": "11h",
    "value": 15
}
]

So... Is this a new resource? like:

loggers/2/data/max?begin=10h&end=12h

or the same resource filtered?

loggers/2/data?begin=10h&end=12h&filter=max

What do you think? thanks!

Upvotes: 1

Views: 74

Answers (1)

Raffaele Rossi
Raffaele Rossi

Reputation: 1109

I suggest a new resource as it's kind-of corresponding to a new method for the given entity.

In my WebApp I use the following format:

  1. To invoke methods of a given entity instance /entity/method/id eg /user/retrieve/5 or /user/settings/5
  2. To invoke static methods /entity/method eg /user/create or /user/oldest
  3. No method would default to the classic "list all" eg /user (I might have decided to do /user/all

Upvotes: 3

Related Questions