2

I have a GPS device for which I need to get:
- the last location
- an history of locations

Regarding the last location, I issue a GET on /devices/id_of_my_gps and it returns the data in json {"latitude":2.3, "longitude":4.5, "timestamp": "2012-04-12T12:32:45Z"}

Regarding the history of location, I'm not sure about the best way to do it.
I'm thinking of issuing a GET on /devices/id_of_my_gps/history and providing "from" and "to" timestamps (the dates between which the history needs to be retrieved) as parameters in the query string. Is that breaking the REST approach ?

UPDATE

Would it be better to send the from/to parameters as data in json: {"from":"2012-04-12T12:32:45Z", "to": "2012-04-15T12:32:45Z"} ?

Luc
  • 15,030
  • 32
  • 113
  • 175

1 Answers1

3

I'm thinking of issuing a GET on /devices/id_of_my_gps/history and providing "from" and "to" timetamps (the dates between which the history needs to be retrieved) as parameters in the query string. Is that breaking the REST approach ?

No. REST doesn't restrict the use of query parameters so there is nothing wrong with your approach.

Would it be better to send the from/to parameters as data in json: {"from":"2012-04-12T12:32:45Z", "to": "2012-04-15T12:32:45Z"} ?

Use the earlier approach. You cannot issue GET and send data in the body as you propose. Entity body is not allowed with GET request so you will have to resort some other HTTP method (PUT or POST) if you need to send data in the entity body which in your case is not semantically correct.

Suresh Kumar
  • 9,697
  • 8
  • 39
  • 51
  • Thanks for your reply. The following command works correctly: curl -H "Accept: application/json" -H "Content-type: application/json" -XGET -d '{"from":"2012-01-01T12:00:00+0200", "to":"2012-05-01T12:00:00+0200"}' 'http://localhost:3000/devices/gps001/history'. Why is this not correct ? – Luc Apr 18 '12 at 09:26
  • See the following SO question for more info http://stackoverflow.com/questions/978061/http-get-with-request-body – Suresh Kumar Apr 18 '12 at 09:32