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”} ?
No. REST doesn’t restrict the use of query parameters so there is nothing wrong with your approach.
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.