Correct formatted REST URL with date ranges

I have a REST URL so that all users are formatted as follows: http://example.com/users

To get an individual user by id: http://example.com/users/12345

To get all custom bids: http://example.com/users/12345/bids

To get all custom bids between two dates: http://example.com/users/12345/bids/?start=01/01/2012&end=01/31/2012

or it should be like this: http://example.com/users/12345/bids/start/01012012/end/01312012

I am leaning towards the URL of the 1st date range since the start and end are not entities in the domain. What is the correct way to format a REST url with a date range?

Thank,

Tom

+43
rest
Mar 09 '12 at 16:11
source share
3 answers

http://example.com/users/12345/bids?start=01-01-2012&end=01-31-2012

Enter your query parameters at the same level as your bids (remove the slash before the question mark). But you probably want to get support if they provide only one query parameter. Therefore, if they provided only a β€œstart”, after that he will receive all bets after this date, or if they provide only β€œend”, he will receive all bets before this date.

The reason is that query parameters are good for GETting a subset of the results from a GET request. They do not go to another level, because the next level is usually one specific element with a unique identifier.

+44
Mar 09 '12 at 16:17
source share

I would go with http://example.com/users/12345/bids?start=2012-01-01&end=2012-01-31 .

  • The query string must not contain a slash.
  • Avoid using a slash in the query string. It will be easier.
+5
Mar 09 '12 at 16:15
source share

If example.com/users/12345 receives a user with the identifier 12345, then in order to get all users by id, he must be example.com/users with the identifier included in the response as a relation. (usually a hyperlink to this resource).

Now, to get them by date ranges, it should be example.com/users/start=01-01-2012&end=01-31-2012

Part 12345 is the identifier of an individual user, this is a resource, so it should not be included in order to get other users.

As a parameter name, it must be meaningful. the start could mean anything, but start_date is more pronounced.

0
Apr 22 '14 at 14:40
source share



All Articles