tags:

views:

98

answers:

3

My idea is to treat URI's in my rest api as a unique resource, except in the context of the client's location, which is stored in a cookie. Are there any downsides to this approach?

A: 

I'd be concerned about caching. Do one request with the user at location A, it gets cached, user moves to B and makes the request again, gets location A version of the request.

John Saunders
+1  A: 

As an API, you should aim at making ease of use for the client programmer a high priority. In many libraries that support HTTP, putting cookies into the HTTP request is more difficult than putting, say, a query parameter into the URL.

Martin v. Löwis
+1  A: 

From a philosophical perspective, it's not really REST if you don't uniquely identify the resource via URL (at least, per my reading of Fielding).

From a practical perspective -- and this is based on experience -- you're in for a world of pain if you require web service calls to use cookies. Primarily because it's a piece of information that has to be managed on a different code path, making your client-side code more complex. You'll also run into issues with domain and proxies (particularly if you share the cookie between the service and a traditional web-app), and it isn't portable between clients.

If you're looking to generate different content based on location, why not use a geolocation service?

Edit: why not make location part of the request URL? You can still use a cookie to store this information, and retrieve it using JavaScript. This would leave your service interface clean, and allow you to easily use the service from other clients.

kdgregory
I actually am using a geolocation service, but users will have the option to select their location. The idea is to always store the location in a cookie so that:a) The user can specify a location once and then it will be persisted in a cookie.b) An ip lookup needn't be done on each request since it's cahced in the cookie after the first lookup.Well, at least that has been my thinking so far...