GET parameters?


Pawel Szymczykowski <makenai@...>
 

Hi all,

I can see that it's pretty easy to specify parameters to a POST request:

RestClient.post 'http://example.com/resource', :param1 => 'one'

..is there a convenience method to do the same for GET? The following doesn't work:

RestClient.get 'http://example.com/resource', :param1 => 'one'

So far, I've had to wrap it in a function that does something like this:

query_string = params.collect { |k,v| "#{k}=#{CGI::escape(v)}" }.join('&')
RestClient.get "#{url}?#{query_string}"

..but surely there must be a better way that I'm missing?

Thanks!


Archiloque <code@...>
 

There's not better way to pass your parameters for a get, sorry

A.


Le 22 mai 2010 à 14:19, Pawel Szymczykowski a écrit :

Hi all,

I can see that it's pretty easy to specify parameters to a POST request:

RestClient.post 'http://example.com/resource', :param1 => 'one'

..is there a convenience method to do the same for GET? The following doesn't work:

RestClient.get 'http://example.com/resource', :param1 => 'one'

So far, I've had to wrap it in a function that does something like this:

query_string = params.collect { |k,v| "#{k}=#{CGI::escape(v)}" }.join('&')
RestClient.get "#{url}?#{query_string}"

..but surely there must be a better way that I'm missing?

Thanks!


Adam Wiggins <adam@...>
 

Lots of people have asked for this feature, though, would be great to
add. Would be confusing with the way that get can take header
parameters. Maybe slip it in with a special parameter "params"?

RestClient.get "http://www.google.com/search", :params => { :q =>
'mysearch' }, :accept => 'text/html'


code@...
 

Lots of people have asked for this feature, though, would be great to
add. Would be confusing with the way that get can take header
parameters. Maybe slip it in with a special parameter "params"?
the hackish/usefulness ratio sounds good, will give it a try

/A.


Archiloque <code@...>
 

Le 25 mai 2010 à 08:15, code@... a écrit :

Lots of people have asked for this feature, though, would be great to
add. Would be confusing with the way that get can take header
parameters. Maybe slip it in with a special parameter "params"?
the hackish/usefulness ratio sounds good, will give it a try

/A.
http://github.com/archiloque/rest-client/tree/master
updated an example : RestClient.get 'https://user:password@example.com/private/resource', {:accept => :json, :params => {'foo' => 'bar'}}

A.


Adam Wiggins <adam@...>
 

Nice! Though might want to mention this in a separate section of the
docs, or at least break it apart from the private resource example so
that it's more clear that this is a distinct feature.

Adam


Cyril Rohr <cyril.rohr@...>
 

On 25 May 2010, at 20:08, Archiloque wrote:


http://github.com/archiloque/rest-client/tree/master
updated an example : RestClient.get 'https://user:password@example.com/private/resource', {:accept => :json, :params => {'foo' => 'bar'}}

A.
Personally I would use the keyword "query" instead of "params" since it is the name already used by libraries such as URI to access the *query* parameters of a URI...

Cyril
--
http://crohr.me


Archiloque <code@...>
 

Le 31 mai 2010 à 17:51, Cyril Rohr a écrit :

On 25 May 2010, at 20:08, Archiloque wrote:


http://github.com/archiloque/rest-client/tree/master
updated an example : RestClient.get 'https://user:password@example.com/private/resource', {:accept => :json, :params => {'foo' => 'bar'}}

A.
Personally I would use the keyword "query" instead of "params" since it is the name already used by libraries such as URI to access the *query* parameters of a URI...

Cyril
On the other side params is the the method name to access the query parameters in rack and as a consequences in many server-side frameworks, so I prefer params

A.