-1

i am new to ruby RestClient. i have search many example of this restclient and in docruby. For me is important while using ruby restclient, to get the data very fast. But some are not answers, this is why i would like to question to you all.

i am working on this ruby restclient example Code:

restClient = RestClient::Request.new(       
    :method     => :get,
    :url        => url,
    :verify_ssl => true, #required using https
    :content_type => :json,
    :accept => :json,             
    :headers    => {
        :Authorization => "Bearer #{token}",
    }
)   
result = restClient.execute()

My first question is what is different of using double point and astrophobe?

restClient = RestClient::Request.new(
    :method     => :get,
    :method     => 'get',
    ...
)

Second question is, is sequences/order in Code important like first url then method or method then url and so on?

restClient = RestClient::Request.new(
    :url        => :url,
    :method     => :get,
    ...
)

#or

restClient = RestClient::Request.new(
    :method     => :get,
    :url        => :url,
    ...
)

third question is, about accept to put in headers. some put accept and content-type in headers and some not, what is different?

restClient = RestClient::Request.new(
    :content_type => 'application/json',
    :accept       => 'application/json',
    
    #or
    
    :headers    => {
        'hello-token' => "Bearer #{token}",
        'content_type'=> 'application/json',
        'ACCEPT'      => 'application/json'
    }
    
)
goethe
  • 35
  • 8
  • 1
    If you have three questions, please ask three questions, so that every question can get the answer it deserves. However, please note that questions #1 and #2 have nothing to do with `RestClient`, they are just basic Ruby syntax questions that are covered in every basic Ruby tutorial, and have been asked and answered multiple times already on [so]. Also, it would help if you could explain *what* precisely is unclear to you about the documentation, so that answerers don't waste their time telling you stuff you already know, or stuff you already read and didn't understand. – Jörg W Mittag Aug 07 '20 at 10:31

1 Answers1

1

What is different of using double point and astrophobe?

:get is a Symbol, 'get' is a String.

It depends on the implementation of the gem if the gem is able to process both. Because the RestClient documentation uses a Symbol in its examples I would recommend doing the same.

But actually – at least in its current version - it doesn' make a difference because the gem translate the argument internally into a string anyway (see initialize and normalize_method)

is sequences/order in Code important

In theory, a hash is an unordered data structure. Therefore the order should not be important in this case. But keep in mind that Ruby's implementation of a hash is actually preserving the order in which the keys are inserted when iterating the hash.

Accept headers

I didn't find any example in the gem's documentation in which they used the first version. Did you actually try both versions? I would be surprised when both worked. Therefore I suggest using the header: version.

spickermann
  • 100,941
  • 9
  • 101
  • 131