exports.urls = ["", "myActions"];
or to some other request dispatching function implementing its own
dispatching logic:
exports.urls = ["", "myWebappFramwork", "dispatch"];
From its Helma legacy, Ringo has leaned to this generic, high level
style of mapping (auto-mapping to the exported functions of a module
is similar to Helma's mapping to actions of a HopObject). Because of
this, the means Ringo provides for specific url mappings may be a
little bit underdeveloped.
One thing people may be missing is dispatching based on HTTP method.
The last few days I've been thinking about how we could integrate this
into our current webapp dispatch syntax (or change the whole mechanism
to make it fit in). One idea I'm playing with is to allow including
the HTTP method in the pattern string, separated from the path pattern
with a space character:
exports.urls = [
["GET ^/document", "actions", "getDocument"],
["POST ^/document", "actions", "postDocument"],
["PUT ^/document", "actions", "putDocument"],
["DELETE ^/document", "actions", "deleteDocument"]
];
What I like about this is that it kind of reflects part of the first
line of a HTTP request:
GET /document/234987234 HTTP/1.1
What do you think?
Hannes
First of all, really great to see some further thoughts and discussion on this.
Well, here's another (still pretty rough) idea thrown in:
// an-app/config.js
// [...]
exports.urls = [
["^/", "./actions"]
];
// an-app/actions.js
// [...]
// GET /documents
exports.GET.documents = function (req) {
// Do something.
};
// GET /documents/{id}
exports.GET.documents = function (req, id) {
// Do something.
};
// POST /documents/{id}
exports.POST.documents = function (req, id) {
// Do something.
};
// PUT /documents/{id}
exports.PUT.documents = function (req, id) {
// Do something.
};
// DELETE /documents/{id}
exports.DEL.documents = function (req, id) {
// Do something.
};
-- Robi
Well, the roughness shows, e.g., in that the above won't work this
way, of course (as in no method overloading in JS). :)
-- Robi
Another iteration of the idea which could possibly actually work (somehow):
http://gist.github.com/427546
-- Robi
These are interesting ideas! However i think I would put it the other way round:
exports.documents = {
GET: function(req) {...},
POST: function(req) {...},
DELETE: function(req) {...}
};
To me it feels more natural this way around.
hannes
> -- Robi
>
> --
> You received this message because you are subscribed to the Google Groups "RingoJS" group.
> To post to this group, send email to rin...@googlegroups.com.
> To unsubscribe from this group, send email to ringojs+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ringojs?hl=en.
>
>
It would add additional unnecessary code. And sometimes you have those
cases when you want to respond with the same result irrespective of HTTP
method.
--
Emilis Dambauskas
emil...@gmail.com
gsm: +370-686-07732
irc: emili...@irc.freenode.net
http://emilis.info
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GAT/CC/MC/O dpu(-) s:- a- C++ UBLHS++ P(+) L+++ E--- W+++$ N+ o-- K? !w O? M-@ V? PS+(--) PE Y+>++ PGP t- 5? X+@ R- !tv b+ DI++++ D G e++ h---- r+++ y++++
------END GEEK CODE BLOCK------