I’m just learning REST and trying to figure out how to apply it in practice. I have a sampling of data that I want to query, but I’m not sure how the URLs are meant to be formed, i.e. where I put the query. For example, for querying the most recent 100 data records:
GET http://data.com/data/latest/100
GET http://data.com/data?amount=100
which of the previous two queries is the better, and why? And the same for the following:
GET http://data.com/data/latest-days/2
GET http://data.com/data?days=2
GET http://data.com/data?fromDate=01-01-2000
Thanks in advance.
Personally, I would use the query string format in this case. If your
/datapath is returning all of the data, and you would like to perform this type of query, I believe it makes the most sense. You could also pass query string parameters such as?since=01-01-2000to get entries after a specified date or pass column names such as?category=clothingto retrieve all entries with category equaling clothing.Additionally, you would want paths such as
/data/{id}to be available to retrieve certain entries given their unique id.