[Dancer-users] one route, different actions based on context

Puneet Kishor punk.kish at gmail.com
Fri Dec 24 20:48:06 CET 2010


Adding to my own email...

Puneet Kishor wrote:
> I am fairly certain I saw mention of this in the docs, but I can't find
> it now, so here goes --
>
> The route `get '/all'` is invoked from the browser by going to
> http://application/foo/all. This causes a template to be rendered with
> all the "chrome" of the application, the buttons, the forms, the logos,
> bylines, etc. The crap that Edward Tufte refers to as "administrivia."
> This template is appropriately filled with data from a query for "all"
> foo widgets from the data store.
>
> Well, I also want `get '/all'` to callable from the command line. So, if
> the user types
>
> $ curl http://application/foo/all
>
> a json stream of all the foo widgets is returned.
>
> How do I accomplish the above? That is, have a single route called `get
> '/all'` and yet be able to call it either from a browser or from a
> command line but with different "stuff" returned? Seems like the ajax
> plugin is not the solution? or is it? I can't make out from its
> documentation.
>
>


I guess what I want is to determine where the request is coming from, 
perhaps via the headers. If it is an XHR then send only the json stream, 
otherwise, send back the template.


-- 
Puneet Kishor http://punkish.org
Carbon Model http://carbonmodel.org
Charter Member, Open Source Geospatial Foundation http://www.osgeo.org
Science Fellow http://creativecommons.org/about/people/fellows#puneetkishor
Nelson Institute, UW-Madison http://www.nelson.wisc.edu
---------------------------------------------------------------------------
Assertions are politics; backing up assertions with evidence is science
===========================================================================


More information about the Dancer-users mailing list