[Dancer-users] one route, different actions based on context
Puneet Kishor
punk.kish at gmail.com
Fri Dec 24 22:35:06 CET 2010
Adding again to my own email...
Puneet Kishor wrote:
> 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.
>
>
Nope, that is not what I want. What I want is to send back the template
only if being request via a browser as a regular, non-Ajax request (how
should I determine that?). Otherwise, if it is being called via Ajax or
from the command line via curl or lwp or whatever, a json stream should
be returned.
--
Puneet Kishor
More information about the Dancer-users
mailing list