1

I'm updating my rest-client gem from 1.8 to 2.0.

On 1.8 it sends an array of params on a get request as my-url?ids=1,2,3,4. But on 2.0 it uses duplicated keys like my-url?ids=1&ids=2&ids=3. For reasons beyond the context of this question, our back end does NOT support the new multiple keys syntax (ok, it supports it, but we'll have to make a big refactor). So I'd like to know if there's a way to use the 2.0 client version and keep sending get array requests with only one key and separated by comma as before?

2 Answers 2

2

Based on the rest-client docs https://github.com/rest-client/rest-client#query-parameters it seems your only option would be to serialize the parameters yourself and add them to the URL as the query string.

If you don't like this behavior and want more control, just serialize params yourself (e.g. with URI.encode_www_form) and add the query string to the URL directly for GET parameters or pass the payload as a string for POST requests.

If you provide some sample code on how you're using the gem, we could help out a bit better with sample answers.

Sign up to request clarification or add additional context in comments.

Comments

0

Ok yeah Leo Correa was right, so what I had to do is replace my old code

params = {
    partner_key: @partner,
    resources: ["front_end_config", "gui_settings"]
}
@response = JSON.parse( RestClient.get( "#{api_base_uri}/partner_config.json", params: params.merge({multipart:true}) ) )

with this new one, serializing and encoding by myself...

params = {
    partner_key: @partner,
    resources: '["front_end_config", "gui_settings"]'
}
params = URI.encode_www_form(params.merge({multipart:true}))
@response = JSON.parse( RestClient.get( "#{api_base_uri}/partner_config.json?#{params}" ) )

It's ugly as hell, but it worked for me. If there's some other idea on how to make it better, I'd appreciate.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.