[Prototype-core] Ajax.Request Interface

2009-12-11 Thread Joran Greef
From:
https://prototype.lighthouseapp.com/projects/8886/tickets/961-ajaxrequestsetrequestheaders-sets-content-type-header-as-content-type-and-sets-it-regardless-of-whether-its-provided-to-the-ajaxrequest-interface-and-other-issues

The interface of the Ajax.Request object has a few problems:

1. Too many implicit defaults (Accept, Content-Type, charset etc).
2. Does not model the interface of HTTP.
3. 'requestHeaders' are provided as an option, 'encoding' as an
option, 'contentType' as an option, when 'encoding' should be
specified as 'charset' as part of the 'Content-Type' header which
should be a subset of 'requestHeaders'.
4. If the request headers are provided as 'requestHeaders' then the
request body needs to be provided as 'requestBody' not as 'postBody'.
REST concepts such as method, uri, headers, parameters, representation
should not be fused (e.g. 'XMLHttpRequest' which fuses the content
type and the protocol, or 'postBody' which fuses the method and the
representation).
5. 'requestHeaders' smells.
6. For method overriding, the 'X-Http-Method-Override' header would be
better than the '_method' parameter.
7. It's not memorable. One has to keep looking up the Ajax options in
the documentation (and where things get implicit, in the
implementation).

Here's a better (and more memorable) interface:

Http.get/set/unset(uri, options) where 'options' has the following
properties: 'headers', 'parameters', 'representation', onSuccess,
'onTimeout', 'onFailure', and where the response object passed to the
callbacks has the following properties: 'status', 'headers',
'representation'.

Http.delete can't be used as 'delete' is a reserved word. Http.set
does a POST with the 'X-Http-Method-Override' header set to 'PUT' so
as to be idempotent where the server supports PUT. Http.unset does a
POST with the 'X-Http-Method-Override' header set to 'DELETE'.

-- 
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en


Re: [Prototype-core] Ajax.Request Interface

2009-12-11 Thread artemy tregubenko
Using proposed interface, how do I do POST? How do I do OPTIONS or some  
custom method? Why use `set` and not `put`? Why use 'representation' and  
not 'body'?

I would say your proposal isn't much more memorable than existing.

On Fri, 11 Dec 2009 16:07:53 +0300, Joran Greef jorangr...@gmail.com  
wrote:

 'representation'


-- 
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en


Re: [Prototype-core] Ajax.Request Interface

2009-12-11 Thread Andrew Dupont
Thanks, Joran. We have plans to start from scratch with Ajax in  
Prototype 2.0; I think our ideas are mostly along the same lines as  
yours.

I also want to fix some of the annoyances of the current API,  
hopefully for 1.7.

Cheers,
Andrew


On Dec 11, 2009, at 7:07 AM, Joran Greef wrote:

 From:
 https://prototype.lighthouseapp.com/projects/8886/tickets/961-ajaxrequestsetrequestheaders-sets-content-type-header-as-content-type-and-sets-it-regardless-of-whether-its-provided-to-the-ajaxrequest-interface-and-other-issues

 The interface of the Ajax.Request object has a few problems:

 1. Too many implicit defaults (Accept, Content-Type, charset etc).
 2. Does not model the interface of HTTP.
 3. 'requestHeaders' are provided as an option, 'encoding' as an
 option, 'contentType' as an option, when 'encoding' should be
 specified as 'charset' as part of the 'Content-Type' header which
 should be a subset of 'requestHeaders'.
 4. If the request headers are provided as 'requestHeaders' then the
 request body needs to be provided as 'requestBody' not as 'postBody'.
 REST concepts such as method, uri, headers, parameters, representation
 should not be fused (e.g. 'XMLHttpRequest' which fuses the content
 type and the protocol, or 'postBody' which fuses the method and the
 representation).
 5. 'requestHeaders' smells.
 6. For method overriding, the 'X-Http-Method-Override' header would be
 better than the '_method' parameter.
 7. It's not memorable. One has to keep looking up the Ajax options in
 the documentation (and where things get implicit, in the
 implementation).

 Here's a better (and more memorable) interface:

 Http.get/set/unset(uri, options) where 'options' has the following
 properties: 'headers', 'parameters', 'representation', onSuccess,
 'onTimeout', 'onFailure', and where the response object passed to the
 callbacks has the following properties: 'status', 'headers',
 'representation'.

 Http.delete can't be used as 'delete' is a reserved word. Http.set
 does a POST with the 'X-Http-Method-Override' header set to 'PUT' so
 as to be idempotent where the server supports PUT. Http.unset does a
 POST with the 'X-Http-Method-Override' header set to 'DELETE'.

 -- 
 You received this message because you are subscribed to the Google  
 Groups Prototype: Core group.
 To post to this group, send email to prototype-core@googlegroups.com
 To unsubscribe from this group, send email to 
 prototype-core-unsubscr...@googlegroups.com
 For more options, visit this group at 
 http://groups.google.com/group/prototype-core?hl=en

-- 
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en


[Prototype-core] Re: Ajax.Request Interface

2009-12-11 Thread Joran Greef
Thanks Artemy, 'set' vs 'put' took some consideration. Basically: many
Javascript APIs use 'get', 'set', 'unset' methods. I used to use POST
(as in 'create') but now find it's easier to deal with network failure
using only PUT (as in 'set') as POST is not idempotent. As mentioned
above, where the server supports PUT, your Http.set would be upgraded
from a POST to a PUT. Where it does not, your Http.set would remain a
POST so you get the best of both worlds. I guess you could do
Http.Get, Http.Post, Http.Put and Http.Delete static methods to get
around 'delete' being reserved. This then is quite extensible, one
downside being that the method names are then upper camelCase.
Although I would argue for point 2 above, I do think that Http.set,
get, unset sits better next to other Javascript APIs. Excuse me if
memorable came off as better: what I meant is easy to remember.

Thanks Andrew, looking forward.

-- 
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en


[Prototype-core] Re: Ajax.Request Interface

2009-12-11 Thread Joran Greef
Re: Why use 'representation' and not 'body'?

REST = Representational State Transfer.

-- 
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en


Re: [Prototype-core] Re: parameters Encoding differents in Ajax Request

2009-12-11 Thread Allen Madsen
Does it break if you use htmlentities($searchParameter,ENT_COMPAT,'UTF-8');
for all browsers?

Allen Madsen
http://www.allenmadsen.com


On Fri, Dec 11, 2009 at 2:42 PM, John john@gmail.com wrote:


 the page has this meta-tag
  meta http-equiv=Content-Type content=text/html;
 charset=utf-8 /
 but I get the same bug :(


 On 3 dic, 07:24, Allen Madsen bla...@gmail.com wrote:
  Try setting the page encoding. For example, for html use:
  meta http-equiv=Content-Type content=text/html; charset=utf-8
 
  or for xhtml use:
  ?xml version=1.0 encoding=utf-8?
 
  Though, I'm not sure this will fix your problem. It's just a guess.
 
  Allen Madsenhttp://www.allenmadsen.com
 
  On Wed, Dec 2, 2009 at 5:33 PM, John john@gmail.com wrote:
   If I sent a parameter with bogotá value over this code
   new Ajax.Request(url, {
onSuccess: function(response) {
 //code
   }
   ,parameters:'search=bogotá'
   });
 
   When this arrived to php script through Mozilla  I need use
   htmlentities($searchParameter,ENT_COMPAT,'UTF-8');
   php function  to get the acute;entity.
 
   but in Internet explorer I need use  htmlentities($searchParameter);
   without 'UT8-Charset' ,
   to get the acute;entity.
 
   I think this doesn't have to be different between browsers.
 
   I tried with enconding parameter set to UTF-8 in the Ajax Request,
   but I got the same results.
 
   --
   You received this message because you are subscribed to the Google
 Groups Prototype: Core group.
   To post to this group, send email to prototype-core@googlegroups.com
   To unsubscribe from this group, send email to
 prototype-core-unsubscr...@googlegroups.com
   For more options, visit this group athttp://
 groups.google.com/group/prototype-core?hl=en

 --
 You received this message because you are subscribed to the Google Groups
 Prototype: Core group.
 To post to this group, send email to prototype-core@googlegroups.com
 To unsubscribe from this group, send email to
 prototype-core-unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/prototype-core?hl=en


-- 
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en