You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Richard Dallaway <ri...@dallaway.com> on 2003/01/02 13:01:05 UTC

Moving addParameter in HttpMethod interface

I was wondering if anyone else would find this useful (or if it's just 
me)...

I'm considering offering some diffs to make addParameter(String,String) 
available in HttpMethod.  The thinking being that the interface for 
adding parameters to a request would be easier to use (more consistent, 
simpler).  E.g., you could say:

HttpMethod method = new GetMethod(whatever);
or
HttpMethod method = new PostMethod(whatever);

...and then do...

method.addParameter("foo", "blah");

..in both cases.

At the moment if you find out you need to switch from GET to POST (and 
yes, it has happened to me), then you need to rejigg the way parameters 
are set up.  Obviously it's not a big deal, but I just felt it's 
something that could be easier for the user.

For a GetMethod addParameter() would have to play nicely with 
setQueryString() -- I was thinking addParameter would append to the 
query string.

Would something like that be useful or is it insane?

Cheers
Richard


Re: Moving addParameter in HttpMethod interface

Posted by Richard Dallaway <ri...@dallaway.com>.
Jeff Dever wrote:
 > Only Post has "parameters".  These are distinct from "query arguments".
 >  Parameters are URL encoded and sent in the request body where query
 > arguments are URL encoded and sent as part of the request line.

Jeff... ok, I see what you're saying. Thanks for clarifying that.   I 
was thinking addParameter could  change (that is, append to) the query 
string for a GET method..  So this wouldn't  be "adding a parameter" in 
the strict sense that you describe, but would be a simple convenience to 
the user of the API who wanted to add a  "property" to a request 
regardless of what kind of method they were using.

I guess it's a trade-off between being close to the HTTP spec (in the 
terminology used) and providing an abstraction for a user of the API.
I may yet play with the code and try this out to see how it feels, in 
the interests of "Have[ing] an API which should be as simple to use as 
possible".

Richard






Re: Moving addParameter in HttpMethod interface

Posted by Jeff Dever <js...@sympatico.ca>.
Hey Richard,

Only Post has "parameters".  These are distinct from "query arguments".
  Parameters are URL encoded and sent in the request body where query
arguments are URL encoded and sent as part of the request line.

So parameters do not belong in the base class, but only in the
specialized classes that actually use them.

-jsd


Richard Dallaway wrote:

> I was wondering if anyone else would find this useful (or if it's just 
> me)...
>
> I'm considering offering some diffs to make 
> addParameter(String,String) available in HttpMethod.  The thinking 
> being that the interface for adding parameters to a request would be 
> easier to use (more consistent, simpler).  E.g., you could say:
>
> HttpMethod method = new GetMethod(whatever);
> or
> HttpMethod method = new PostMethod(whatever);
>
> ...and then do...
>
> method.addParameter("foo", "blah");
>
> ..in both cases.
>
> At the moment if you find out you need to switch from GET to POST (and 
> yes, it has happened to me), then you need to rejigg the way 
> parameters are set up.  Obviously it's not a big deal, but I just felt 
> it's something that could be easier for the user.
>
> For a GetMethod addParameter() would have to play nicely with 
> setQueryString() -- I was thinking addParameter would append to the 
> query string.
>
> Would something like that be useful or is it insane?
>
> Cheers
> Richard
>
>
> -- 
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
>
>