Hi Thierry,
Thank you. I know, however, I find it "cleaner" that prototype will "delete"
and "put" from within without using the "_method" param.
So that is why I decided to change its behavior a bit :).
Gal.
----- Original Message -----
From: "Thierry Boileau" <[EMAIL PROTECTED]>
To: <discuss@restlet.tigris.org>
Sent: Monday, July 21, 2008 11:00 AM
Subject: Re: Using Prototype.js with Restlet
Hello Eric and Gal,
you can also use a mechanism based on the URI of the resource that allows
to make PUT, DELETE requests via POST. It consists in adding a "method"
parameter in the query part of the resource's URI.
See this page for more details :
http://www.restlet.org/documentation/1.1/faq#19
In a few word, if you want to PUT to http://myserver/myresource, just POST
the same entity to http://myserver/myresource?method=put
best regards,
Thierry Boileau
Hi,
I have changed prototype instead.
for prototype ver 1.6.0.2
around line 1193 I replace with the following:
if (!['get', 'post', 'put', 'delete'].include(this.method)) {
// simulate other verbs over post
params['_method'] = this.method;
this.method = 'post';
}
just adding the put and delete enables you to use thos methods without
any changes to restlet.
However, if you wish to add "body" to your put and delete methods you
would also need to change line 1222 to enable send body with those
methods. As it is, prototype will add body only to post.
HTH,
Gal
----- Original Message ----- From: "Eric Vuillermet"
<[EMAIL PROTECTED]>
To: <discuss@restlet.tigris.org>
Sent: Monday, July 21, 2008 3:53 AM
Subject: Using Prototype.js with Restlet
Hi everyone,
I have just started using Restlet a week back so this might be a newbie
question, sorry!
I created a simple application using prototype.js for the front-end
talking to
a Restlet back-end.
I would like the JS code to be as clean as possible, so my DELETE/PUT
requests
from JavaScript look like DELETE/PUT requests, and I used the
PrototypeFinder
class from the Restlet wiki
(http://wiki.restlet.org/docs_1.1/g1/13-restlet/29-
restlet/99-restlet/52-restlet.html) to support the tunneling of
DELETE/PUT
from Prototype through POST. Prototype adds a form parameter called
'_method'
to the POST body, and the PrototypeFinder class reads that parameter to
set
the correct method on the incoming request.
The problem it seems is that when the PrototypeFinder class read the
_method
parameter, it does that by reading the entire input entity as a form.
That's
OK for DELETE, but the problem is, if I want to have the JavaScript do a
normal POST, the handlePost method of the Resource class will respond
"Missing
request entity", because the input entity has already been read by
PrototypeFinder before reaching my resource's post method.
Has anyone else tried to use Prototype.js and Restlet together? Have
they run
into this same issue? How did they solve it?
FYI: Here is the PrototypeFinder class I am using (same as the one on
the
Restlet wiki):
public class PrototypeFinder extends Finder {
public PrototypeFinder(Context context, Class<? extends Resource>
targetClass) {
super(context, targetClass);
}
public void handle(Request request, Response response) {
Parameter p = request.getEntityAsForm().getFirst("_method"); // This is
where Prototype.js puts the real method name
request.setMethod(null != p ? Method.valueOf(p.getValue()) :
request.getMethod());
super.handle(request, response);
}
}
Thanks for your help!
Eric