On 14 nov, 15:34, jake H <[EMAIL PROTECTED]> wrote:
> Hello ,
> I m trying to implement Rest 'commands' , like PUT or DELETE with
> RequestBuilder.

s/implements Rest 'commands'/use HTTP methods/

> As much as i read, i saw that we can avoid them by using POST and
> modifying the header.

You'd first have to understand the "why": Safari 2's XMLHTTPRequest
only allows GET and POST.
(actually, there are HTTP proxies too which don't like HTTP methods
other than GET and POST)

So, if Safari 2 support is not important for you, you can *safely*
issue *real* DELETE and PUT requests.
For this, you'll have to use a tiny little hack: using the protected
constructor taking a String as method argument, by creating a subclass
overriding nothing. That's what the code snippet you included (see
below too) does. I have a preference for the following code:

   RequestBuilder builder = new RequestBuilder("PUT", url) { /*
nothing to override */ };

(i.e. using an anonymous subclass).

> Can someone share an example?

If Safari 2 support matters, then yes "HTTP method override" is
unfortunately the way to go. This also means you'll have to add
support for this on the server side.

This example uses a request header, like the GData APIs:

   RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
url);
   builder.setHeader("X-HTTP-Method-Override", "PUT");
   builder.setHeader("Content-Type", "text/plain");
   builder.sendRequest("new content of the resource",
myRequestCallback);

> Secondly i came accross with this
>
> public class DeleteRequestBuilder extends RequestBuilder {
>     public DeleteRequestBuilder(String url) {
>      super("DELETE", url);
>
>   }
>
> }
>
> In manning's book GWT in Practice. Any idea how it can be used?
>
> Something like that?
>
> DeleteRequestBuilder requestBuilder = new DeleteRequestBuilder(url);
>     try {
>      //data
>       requestBuilder.sendRequest(data_to_deleted?, new
> ResponseTextHandler());
>    ..
> ....

Except that "data_to_deleted?" must be the empty string (the thing to
be deleted is identified by the URL) and the second argument has to be
a RequestCallback rather than a ResponseTexthandler; yes.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to