Hi Chen, yes, there is a difference between AJAX requests and classic "web form" POST requests. AJAX allows you to send HTTP requests such as PUT (It may depends on the browser, though) with correct content-type, as a classic client. Here are the request/response headers sent by Firefox 3.6 when clicking on the "update" button on the sample app [1] illustrating the "first system" sample app [2]:
PUT /contacts/123 HTTP/1.1 Host: restlet-example-serialization.appspot.com User-Agent: Restlet-Framework/2.0snapshot Accept: application/x-java-serialized-object+gwt Accept-Language: fr,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Content-Type: application/x-java-serialized-object+gwt; charset=UTF-8 Referer: http://restlet-example-serialization.appspot.com/org_restlet_example_gae_serialization/747F0EF6A10597E5888F82DD3E9494F8.cache.html Content-Length: 242 HTTP/1.1 200 OK Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept Accept-Ranges: bytes Date: Tue, 13 Apr 2010 12:22:37 GMT Content-Type: text/html Server: Google Frontend Content-Length: 0 >It is not clear to me why I need a custom converter? Well, it's not clear to me too. :) I think I've overinterpreted your questions. If I understand well, you send a POST request (I'm not clear if it is via AJAX or a Web form). For sure it won't work since the resource accepts only GET and PUT. In the case you send such POST requests because of Web form limitations, you can workaround this by leveraging the TunnelService [3]: - make sure application#tunnelService#methodTunnel is turned on. - update the target URL, by adding a "method=put" (for example) parameter in the query. The Tunnel filter is in charge to update the method of the request. Now, let's have a look at the body of your request. You design the resource as follow: @Put("json") public void insertItem(Item myItem){ //insert item into DataStore } By doing so, you rely on registered converters in order to convert a JSON representation (the source representation) into an Item instance (the target object). If the source representation has not the desired media type, it will fail and return a 405 status. If any converter is unable to generate the conversion to the target type, it will also fail. Having said that, the default converter supports such methods: @Put public void insertItem(Form myItemAsAForm){ //insert item into DataStore } The Xstream (patched) converter, or Jackson converter should be able to support such annotated method as soon as the source representation has a "json" media type and its content is compatible with the framework expectations: @Put("json") public void insertItem(Item myItem){ //insert item into DataStore } I hope this will help you a little bit. Feel free, of course, to ask for more details. >btw - GET operations are very limited since you cannot upload large JSON >objects because of URL length limitations (especially on mobile devices) Well, I'm not sure to fully understand. Representations are not to be sent via the URL, in query parameters. That's a very bad idea. Best regards, Thierry Boileau [1] http://restlet-example-serialization.appspot.com/Org_restlet_example_gae_serialization.html [2] http://wiki.restlet.org/docs_2.0/13-restlet/303-restlet.html [3] http://wiki.restlet.org/docs_2.0/13-restlet/207-restlet.html ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2580786

