[Dancer-users] a Dance for the REST of us
punk.kish at gmail.com
Fri Dec 24 00:42:41 CET 2010
I have widgets called "foo," and I am building web app that will also
serve as a RESTful app for data access via the command line. All "foo"
related routes are packaged together, and are loaded via
`load_app "app::foo", prefix => "/foo"`
so that `get '/:foo_id'` really become `http://server/foo/:foo_id`.
My routes are
1. get '/'
Returns a welcome page via a full html request. A full html request is
where a full web page is loaded, as opposed to an ajax request where
only a part of the web page is refreshed.
2. get '/all'
Returns minimal info for all valid "foo" from the data store via a full
html request. However, I would also like to return them as a json string
via the command line. Now, when requested via the web browser, this
method should really return only some minimal info for each "foo."
Clicking on any specific "foo" should fire #3 below to get its details
-- a typical drill-down application. However, when requested via the
commandline, there should be an option to return *all* the details, with
some checks, so that gigabytes of data are not returned.
3. get '/:foo_id'
Returns all the details for a specific "foo" as a json string via an
4. get '/new'
Returns a page to begin constructing a new "foo" in the browser via a
full html request. There is no equivalent command line method for this.
5. post '/save'
Saves a new "foo" created in #4 or above, or via a command line method.
In other words, a user should be able to supply in a json string via the
command line everything that a user would create interactively in #4 above.
6. get '/delete/:foo_id'
This method removed a specific foo. Now, two things I don't understand
about this -- one, of course, in a RESTful app, this would be a DELETE
method. This is a bit confusing to me -- is the HTTP get (I am using a
lowercase 'get') not the same as a REST GET (using an uppercase get)? In
other words, can I use a `get` to perform a `DELETE`? Two, how do I send
authentication? I don't want Sukrieh deleting Sawyer's widget.
In fact, this authentication theme runs through all the routes -- do I
just pass a session token for authentication with every route?
Finally, should #3 be the last route? Else, how do I differentiate
between `get '/delete/5'` and `get '/5'` and `get '/all'`?
Thanks in advance for a quick lesson, whosoever cares to give one.
More information about the Dancer-users