[Dancer-users] RESTful applications in Dancer

Gabor Szabo szabgab at gmail.com
Mon Dec 20 15:22:28 CET 2010


hi,

I have a general web related question and then I wonder which of the
answers can be easily implemented in Dancer?

I am building an application that probably will be mostly just send
out serialized data though I am not 100% sure so I might want to
mix in sending out traditional HTML files as well.
So I wonder what is the "best practice" to write RES-ish application,
one that might also serve HTML?

I thought about a few strategies I am going to describe now
using a single route as an example:

1)
/login    always returns HTML
no XML, JSON, YAML interface
old school, no buzzwords here :)


2)
/login         always returns HTML
/login.yml   returns YAML
/login.json  returns JSON
etc. (some of these might be allowed  some might not)

Q: What is the relationship between the HTML and the YAML?
Is the data returned as YAML the same as would be passed to
the template for generating HTML? How?


3)
/login         returns HTML or YAML or JSON depending on the
Accept header of the request.
In order to fetch the YAML response the request needs to supply:
Accept: application/json

I am not sure if HTTP allows multiple Accept headers and if yes then how
should the application behave?

Otherwise the same as 2 above.

4) No HTML responses at all (only some static pages) so
4.2)  the serialization is the same as in 2) based on extension
4.3)  the serialization is the same as in 3) based on Accept header

Are any of these good strategies? Are there other good ones?
Which one can be implemented in Dancer and how?

regards
   Gabor

-- 
Gabor Szabo
http://szabgab.com/


More information about the Dancer-users mailing list