You want code which will infer what your
code is requiring? Sounds tricky, and I doubt you want to run some sort
of meta-parser every time someone visits '/rest'.
Wouldn't it be easier to write the "resources"
data structure (as you have below), maybe as a config file, so you know
what your application's interface is, and use that to a) generate responses
to /rest, b) maybe generate some documentation, (especially if you include
that in the data structure), and c) validate your parameters in the methods,
e.g. creating a hash(ref) guaranteed to contain all those and only those
parameters specified in the config (and using that hash(ref) thereafter
instead of Damcer's parameter function), and then you can guarantee your
code complies with the specification.
Daniel
From:
"Mr. Puneet Kishor"
<punk.kish@gmail.com>
To:
dancer-users <dancer-users@perldancer.org>
Date:
30/09/2011 14:51
Subject:
[Dancer-users]
a REST question immediately followed by a Dancer-implementation question
Sent by:
dancer-users-bounces@perldancer.org
So, I have a lot of methods such as
get '/foo' => { .. };
get '/bar' => { .. };
get '/baz' => { .. };
get '/qux' => { .. };
All the above methods are reachable via a browser in which they depict
some visual representation of the data.
Most of the above methods have their '.:format' counterparts, mostly returning
JSON packets when reached either via the browser or via the command line.
All the methods above return something by default or modified by parameters.
So, "http://server/app/foo"
may work, or may require some parameters as in "http://server/app/foo?age=27&before=yesterday&for=rascals"
I would like to implement a "meta" method, say
get '/rest' => { .. };
which should return a listing of all the methods above, along with their
parameters, if any, and whether those parameters are optional or required.
http://server/app/rest
{"resources": [
{"name":
"foo, "params": [
{"required": [
{"name":
"age", "type": "int"}
]},
{"optional": [
{"name":
"before", "type": "string"}
{"name":
"for", "type": "string"}
]},
]}
]}
In other words, this meta method returns all the resources available at
the http://server/app.
Of course, I could code this for each app, but it would be nice to automate
it.
Suggestions? Ideas?
--
Puneet Kishor
_______________________________________________
Dancer-users mailing list
Dancer-users@perldancer.org
http://www.backup-manager.org/cgi-bin/listinfo/dancer-users