views:

26

answers:

1

I am developing a web app which displays sales from local stores around the United States. The sales and stores listed vary by location. Is there a RESTful URL scheme for describing this information while avoiding duplicate content?

Specifically, the app needs to list local stores, and list items sold at a particular store. Zip (postal) codes seem a convenient way to refer to location, so consider this scheme:

/stores/zip          - list stores near zip, with links to particular stores
/store/name/lat+long - list items at a particular store

There is a problem. The page at /store/name/lat+long needs to link back to the list of stores, but which zip code should it choose? Say it chooses the zip code closest to the lat+long coordinate. A user might arrive at a particular store page from a link on /stores/zipA yet the store page could refer them back to a slightly different list, /stores/zipB.

We could solve that problem by carrying the zip code information forward. So the list at /stores/zip, could link to /store/name/lat+long/zip. This is not logical, however, because all information needed to identify a store is provided by the lat+long coordinate; the zip code is redundant. In fact the same page content would have duplicate URLs.

Another solution would be to save the last-viewed zip code as a cookie, but that's not RESTful. Is there a solution?

A: 

Add that information as an optional query parameter.

/stores/name/lat+long?search=zip

The /stores/name/lat+long represents the resource uniquely, while the optional query parameter provides the extra information you need for your breadcrumb back to their original search.

If you have links that come from somewhere other than a search for that zip code, then you could just leave the query parameter off. When the query parameter is missing, default to linking back to the closest zip code, or leaving the breadcrumb link off entirely.

Another option would be to just let the browser history do this for you, by using JavaScript to navigate the user to the previous page in their history:

<a href="javascript:history.back()">Back to search</a>
Brian Campbell